/[classpath]/classpath/gnu/java/nio/LongBufferImpl.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/LongBufferImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by mkoch, Tue Mar 11 11:48:51 2003 UTC revision 1.15 by mkoch, Mon May 19 08:36:27 2003 UTC
# Line 1  Line 1 
1  /* LongBufferImpl.java --  /* LongBufferImpl.java --
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    
39  package gnu.java.nio;  package gnu.java.nio;
40    
41  import java.nio.ByteBuffer;  import java.nio.ByteBuffer;
# Line 49  public final class LongBufferImpl extend Line 50  public final class LongBufferImpl extend
50  {  {
51    private boolean readOnly;    private boolean readOnly;
52    
53    public LongBufferImpl(int cap, int off, int lim)    public LongBufferImpl (int capacity)
   {  
     super (cap, lim, off, 0);  
     this.backing_buffer = new long[cap];  
     readOnly = false;  
   }  
   
   public LongBufferImpl(long[] array, int offset, int length)  
   {  
     super (array.length, length, offset, 0);  
     this.backing_buffer = array;  
     readOnly = false;  
   }  
   
   public LongBufferImpl(LongBufferImpl copy)  
   {  
     super (copy.capacity (), copy.limit (), copy.position (), 0);  
     backing_buffer = copy.backing_buffer;  
     readOnly = copy.isReadOnly ();  
   }  
   
   private static native long[] nio_cast (byte[] copy);  
   
   LongBufferImpl (byte[] copy)  
54    {    {
55      super (copy.length, copy.length, 0, 0);      this (new long [capacity], 0, capacity, capacity, 0, -1, false);
     this.backing_buffer = copy != null ? nio_cast (copy) : null;  
     readOnly = false;  
56    }    }
57      
58    private static native byte nio_get_Byte (LongBufferImpl b, int index, int limit);    public LongBufferImpl (long[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
   
   private static native void nio_put_Byte (LongBufferImpl b, int index, int limit, byte value);  
   
   public ByteBuffer asByteBuffer ()  
59    {    {
60      ByteBufferImpl res = new ByteBufferImpl (backing_buffer);      super (buffer, offset, capacity, limit, position, mark);
61      res.limit ((limit () * 1) / 8);      this.readOnly = readOnly;
     return res;  
62    }    }
63      
64    public boolean isReadOnly()    public boolean isReadOnly ()
65    {    {
66      return readOnly;      return readOnly;
67    }    }
68      
69    public LongBuffer slice()    public LongBuffer slice ()
70    {    {
71      return new LongBufferImpl (this);      return new LongBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
72    }    }
73      
74    public LongBuffer duplicate()    public LongBuffer duplicate ()
75    {    {
76      return new LongBufferImpl(this);      return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
77    }    }
78      
79    public LongBuffer asReadOnlyBuffer()    public LongBuffer asReadOnlyBuffer ()
80    {    {
81      LongBufferImpl result = new LongBufferImpl (this);      return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
     result.readOnly = true;  
     return result;  
82    }    }
83      
84    public LongBuffer compact()    public LongBuffer compact ()
85    {    {
86        int copied = 0;
87        
88        while (remaining () > 0)
89          {
90            put (copied, get ());
91            copied++;
92          }
93    
94        position (copied);
95      return this;      return this;
96    }    }
97      
98    public boolean isDirect()    public boolean isDirect ()
99    {    {
100      return false;      return false;
101    }    }
102    
103    final public long get()    /**
104       * Relative get method. Reads the next <code>long</code> from the buffer.
105       */
106      final public long get ()
107    {    {
108      long e = backing_buffer[position()];      long result = backing_buffer [position ()];
109      position(position()+1);      position (position () + 1);
110      return e;      return result;
111    }    }
112      
113    final public LongBuffer put(long b)    /**
114       * Relative put method. Writes <code>value</code> to the next position
115       * in the buffer.
116       *
117       * @exception ReadOnlyBufferException If this buffer is read-only.
118       */
119      final public LongBuffer put (long value)
120    {    {
121      if (readOnly)      if (readOnly)
122        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
123                            
124      backing_buffer[position()] = b;      backing_buffer [position ()] = value;
125      position(position()+1);      position (position () + 1);
126      return this;      return this;
127    }    }
128      
129    final public long get(int index)    /**
130    {     * Absolute get method. Reads the <code>long</code> at position
131      return backing_buffer[index];     * <code>index</code>.
132    }     *
133       * @exception IndexOutOfBoundsException If index is negative or not smaller
134    final public LongBuffer put(int index, long b)     * than the buffer's limit.
135       */
136      final public long get (int index)
137      {
138        return backing_buffer [index];
139      }
140      
141      /**
142       * Absolute put method. Writes <code>value</value> to position
143       * <code>index</code> in the buffer.
144       *
145       * @exception IndexOutOfBoundsException If index is negative or not smaller
146       * than the buffer's limit.
147       * @exception ReadOnlyBufferException If this buffer is read-only.
148       */
149      final public LongBuffer put (int index, long value)
150    {    {
151      if (readOnly)      if (readOnly)
152        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
153                    
154      backing_buffer[index] = b;      backing_buffer [index] = value;
155      return this;      return this;
156    }    }
157      
158    final public ByteOrder order ()    final public ByteOrder order ()
159    {    {
160      return ByteOrder.BIG_ENDIAN;      return ByteOrder.nativeOrder ();
161    }    }
162  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26