diff options
author | Michael Koch <konqueror@gmx.de> | 2003-03-11 08:02:22 +0000 |
---|---|---|
committer | Michael Koch <konqueror@gmx.de> | 2003-03-11 08:02:22 +0000 |
commit | a701ee1919c03deacec6805ef142202b6dae1a87 (patch) | |
tree | b1b9c51a11953db2605b38feffb427cfc6c05fc8 /java/nio/ByteBuffer.java | |
parent | f9a30eb122db77a89c33fac70027c4c673b5f424 (diff) | |
download | classpath-a701ee1919c03deacec6805ef142202b6dae1a87.tar.gz |
2003-03-11 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/CharBufferImpl.java,
gnu/java/nio/DoubleBufferImpl.java,
gnu/java/nio/FloatBufferImpl.java,
gnu/java/nio/IntBufferImpl.java,
gnu/java/nio/LongBufferImpl.java,
gnu/java/nio/MappedDoubleFileBuffer.java,
gnu/java/nio/MappedFloatFileBuffer.java,
gnu/java/nio/MappedIntFileBuffer.java,
gnu/java/nio/MappedLongFileBuffer.java,
gnu/java/nio/MappedShortFileBuffer.java,
gnu/java/nio/ShortBufferImpl.java,
java/nio/ByteBuffer.java,
java/nio/ByteOrder.java,
java/nio/CharBuffer.java,
java/nio/DoubleBuffer.java,
java/nio/FloatBuffer.java,
java/nio/IntBuffer.java,
java/nio/LongBuffer.java,
java/nio/MappedByteBuffer.java,
java/nio/ShortBuffer.java:
Partly merged java.nio from libgcj.
Diffstat (limited to 'java/nio/ByteBuffer.java')
-rw-r--r-- | java/nio/ByteBuffer.java | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/java/nio/ByteBuffer.java b/java/nio/ByteBuffer.java index a00bbd83d..a05a1bcdc 100644 --- a/java/nio/ByteBuffer.java +++ b/java/nio/ByteBuffer.java @@ -45,16 +45,16 @@ import gnu.java.nio.ByteBufferImpl; public abstract class ByteBuffer extends Buffer implements Comparable { private ByteOrder endian = ByteOrder.BIG_ENDIAN; - - protected byte [] backing_buffer; + + int offset; + byte[] backing_buffer; /** * Allocates a new direct byte buffer. */ public static ByteBuffer allocateDirect (int capacity) { - ByteBuffer b = new gnu.java.nio. ByteBufferImpl(capacity, 0, capacity); - return b; + throw new Error ("direct buffers are not implemented"); } /** @@ -75,7 +75,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable { return new ByteBufferImpl (array, offset, length); } - + /** * Wraps a byte array into a buffer. */ @@ -101,10 +101,10 @@ public abstract class ByteBuffer extends Buffer implements Comparable */ public ByteBuffer get (byte[] dst, int offset, int length) { - if ((offset < 0) || - (offset > dst.length) || - (length < 0) || - (length > (dst.length - offset))) + if ((offset < 0) + || (offset > dst.length) + || (length < 0) + || (length > (dst.length - offset))) throw new IndexOutOfBoundsException (); for (int i = offset; i < offset + length; i++) @@ -145,9 +145,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable throw new IllegalArgumentException (); while (src.hasRemaining ()) - { - put (src.get ()); - } + put (src.get ()); return this; } @@ -176,10 +174,8 @@ public abstract class ByteBuffer extends Buffer implements Comparable throw new IndexOutOfBoundsException (); for (int i = offset; i < offset + length; i++) - { - put (src [i]); - } - + put (src [i]); + return this; } @@ -200,9 +196,10 @@ public abstract class ByteBuffer extends Buffer implements Comparable /** * Tells whether or not this buffer is backed by an accessible byte array. */ - public final boolean hasArray() + public final boolean hasArray () { - return (backing_buffer != null); + return (backing_buffer != null + && !isReadOnly ()); } /** @@ -213,7 +210,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable * @exception UnsupportedOperationException If this buffer is not backed * by an accessible array. */ - public final byte[] array() + public final byte[] array () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -233,7 +230,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable * @exception UnsupportedOperationException If this buffer is not backed * by an accessible array. */ - public final int arrayOffset() + public final int arrayOffset () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -241,8 +238,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable if (isReadOnly ()) throw new ReadOnlyBufferException (); - // FIXME: Return correct value - return 0; + return offset; } /** @@ -610,6 +606,9 @@ public abstract class ByteBuffer extends Buffer implements Comparable */ public String toString () { - return ""; + return getClass ().getName () + + "[pos=" + position () + + " lim=" + limit () + + " cap=" + capacity () + "]"; } } |