/[classpath]/classpath/java/nio/ByteBuffer.java
ViewVC logotype

Diff of /classpath/java/nio/ByteBuffer.java

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

revision 1.8 by mkoch, Fri Dec 20 15:28:35 2002 UTC revision 1.9 by mkoch, Tue Mar 11 08:02:23 2003 UTC
# Line 45  import gnu.java.nio.ByteBufferImpl; Line 45  import gnu.java.nio.ByteBufferImpl;
45  public abstract class ByteBuffer extends Buffer implements Comparable  public abstract class ByteBuffer extends Buffer implements Comparable
46  {  {
47    private ByteOrder endian = ByteOrder.BIG_ENDIAN;    private ByteOrder endian = ByteOrder.BIG_ENDIAN;
48      
49    protected byte [] backing_buffer;    int offset;
50      byte[] backing_buffer;
51        
52    /**    /**
53     * Allocates a new direct byte buffer.     * Allocates a new direct byte buffer.
54     */     */
55    public static ByteBuffer allocateDirect (int capacity)    public static ByteBuffer allocateDirect (int capacity)
56    {    {
57      ByteBuffer b = new gnu.java.nio. ByteBufferImpl(capacity, 0, capacity);      throw new Error ("direct buffers are not implemented");
     return b;  
58    }    }
59    
60    /**    /**
# Line 75  public abstract class ByteBuffer extends Line 75  public abstract class ByteBuffer extends
75    {    {
76      return new ByteBufferImpl (array, offset, length);      return new ByteBufferImpl (array, offset, length);
77    }    }
78    
79    /**    /**
80     * Wraps a byte array into a buffer.     * Wraps a byte array into a buffer.
81     */     */
# Line 101  public abstract class ByteBuffer extends Line 101  public abstract class ByteBuffer extends
101     */     */
102    public ByteBuffer get (byte[] dst, int offset, int length)    public ByteBuffer get (byte[] dst, int offset, int length)
103    {    {
104      if ((offset < 0) ||      if ((offset < 0)
105          (offset > dst.length) ||          || (offset > dst.length)
106          (length < 0) ||          || (length < 0)
107          (length > (dst.length - offset)))          || (length > (dst.length - offset)))
108        throw new IndexOutOfBoundsException ();        throw new IndexOutOfBoundsException ();
109    
110      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
# Line 145  public abstract class ByteBuffer extends Line 145  public abstract class ByteBuffer extends
145        throw new IllegalArgumentException ();        throw new IllegalArgumentException ();
146    
147      while (src.hasRemaining ())      while (src.hasRemaining ())
148        {        put (src.get ());
         put (src.get ());  
       }  
149            
150      return this;      return this;
151    }    }
# Line 176  public abstract class ByteBuffer extends Line 174  public abstract class ByteBuffer extends
174        throw new IndexOutOfBoundsException ();        throw new IndexOutOfBoundsException ();
175    
176      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
177        {        put (src [i]);
178          put (src [i]);      
       }  
   
179      return this;      return this;
180    }    }
181    
# Line 200  public abstract class ByteBuffer extends Line 196  public abstract class ByteBuffer extends
196    /**    /**
197     * Tells whether or not this buffer is backed by an accessible byte array.     * Tells whether or not this buffer is backed by an accessible byte array.
198     */     */
199    public final boolean hasArray()    public final boolean hasArray ()
200    {    {
201      return (backing_buffer != null);      return (backing_buffer != null
202                 && !isReadOnly ());
203    }    }
204    
205    /**    /**
# Line 213  public abstract class ByteBuffer extends Line 210  public abstract class ByteBuffer extends
210     * @exception UnsupportedOperationException If this buffer is not backed     * @exception UnsupportedOperationException If this buffer is not backed
211     * by an accessible array.     * by an accessible array.
212     */     */
213    public final byte[] array()    public final byte[] array ()
214    {    {
215      if (backing_buffer == null)      if (backing_buffer == null)
216        throw new UnsupportedOperationException ();        throw new UnsupportedOperationException ();
# Line 233  public abstract class ByteBuffer extends Line 230  public abstract class ByteBuffer extends
230     * @exception UnsupportedOperationException If this buffer is not backed     * @exception UnsupportedOperationException If this buffer is not backed
231     * by an accessible array.     * by an accessible array.
232     */     */
233    public final int arrayOffset()    public final int arrayOffset ()
234    {    {
235      if (backing_buffer == null)      if (backing_buffer == null)
236        throw new UnsupportedOperationException ();        throw new UnsupportedOperationException ();
# Line 241  public abstract class ByteBuffer extends Line 238  public abstract class ByteBuffer extends
238      if (isReadOnly ())      if (isReadOnly ())
239        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
240    
241      // FIXME: Return correct value      return offset;
     return 0;  
242    }    }
243        
244    /**    /**
# Line 610  public abstract class ByteBuffer extends Line 606  public abstract class ByteBuffer extends
606     */     */
607    public String toString ()    public String toString ()
608    {    {
609      return "";      return getClass ().getName () +
610                "[pos=" + position () +
611                " lim=" + limit () +
612                " cap=" + capacity () + "]";
613    }    }
614  }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

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