diff options
author | Per Bothner <per@bothner.com> | 2004-02-16 12:00:33 -0800 |
---|---|---|
committer | Per Bothner <bothner@gcc.gnu.org> | 2004-02-16 12:00:33 -0800 |
commit | 35d0b14df6995e79e84201c45d49ef986f9e0b77 (patch) | |
tree | b053bce2ad70d769c220be5941b4cd3ae9fdccaf /libjava/java/nio/ByteBuffer.java | |
parent | 5693912a7d109bb281efb8bf2ce107a6b516fc1f (diff) | |
download | gcc-35d0b14df6995e79e84201c45d49ef986f9e0b77.zip gcc-35d0b14df6995e79e84201c45d49ef986f9e0b77.tar.gz gcc-35d0b14df6995e79e84201c45d49ef986f9e0b77.tar.bz2 |
ByteBuffer.java (endian): Make non-private so other java.nio classes can inherit it.
* java/nio/ByteBuffer.java (endian): Make non-private so other
java.nio classes can inherit it.
(<init>): Don't bother clearing array_offset.
* java/nio/ByteBuffer.java (allocate): Re-implement using wrap.
* java/nio/ByteBuffer.java (get(byte[],int,int)): Check underflow.
Remove redundant test.
* java/nio/ByteBufferImpl.java (asCharBuffer, asShortBuffer,
asIntBuffer, asLongBuffer, asFloatBuffer, asDoubleBuffer):
Use new XxxViewBufferImpl constructors.
* java/nio/MappedByteBufferImpl.java: Likewise.
* java/nio/DirectByteBufferImpl.java: Likewise.
* java/nio/ByteBufferImpl.java: Remove one constructor.
Inline super in remaining constructor.
* java/nio/ByteBuffer.java: Remove unused constructor.
* java/nio/ByteBufferImpl.java (shiftDown): New optimized method.
* java/nio/ByteBufferImpl.java (get, put): Add array_offset.
* java/nio/DirectByteBufferImpl.java (owner): New field.
(offset): Remove unused field.
(<init>): Modify one and add another constructor. Change callers.
(allocateDirect): Removed - not used.
(getImpl, putImpl): Make static and pass address explicitly,
to make them useful for MappedByteBufferImpl.
(get, put): Check for underflow. Modify for new getImpl.
(getImpl): New native method where target is array.
(get(byte[],int,int)): Use the above.
(adjustAddress): New static native method.
(slice, duplicate, asReadOnly): New implementations.
* java/nio/natDirectByteBufferImpl.cc (getImpl, putImpl, shiftDown,
adjustAddress): New or updated native methods.
From-SVN: r77919
Diffstat (limited to 'libjava/java/nio/ByteBuffer.java')
-rw-r--r-- | libjava/java/nio/ByteBuffer.java | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java index 9ca2061..276b2db 100644 --- a/libjava/java/nio/ByteBuffer.java +++ b/libjava/java/nio/ByteBuffer.java @@ -44,7 +44,7 @@ package java.nio; public abstract class ByteBuffer extends Buffer implements Comparable { - private ByteOrder endian = ByteOrder.BIG_ENDIAN; + ByteOrder endian = ByteOrder.BIG_ENDIAN; int array_offset; byte[] backing_buffer; @@ -52,16 +52,8 @@ public abstract class ByteBuffer extends Buffer ByteBuffer (int capacity, int limit, int position, int mark) { super (capacity, limit, position, mark); - array_offset = 0; } - ByteBuffer (byte[] buffer, int offset, int capacity, int limit, int position, int mark) - { - super (capacity, limit, position, mark); - this.backing_buffer = buffer; - this.array_offset = offset; - } - /** * Allocates a new direct byte buffer. */ @@ -75,7 +67,7 @@ public abstract class ByteBuffer extends Buffer */ public static ByteBuffer allocate (int capacity) { - return new ByteBufferImpl (capacity); + return wrap(new byte[capacity], 0, capacity); } /** @@ -87,6 +79,14 @@ public abstract class ByteBuffer extends Buffer */ final public static ByteBuffer wrap (byte[] array, int offset, int length) { + // FIXME: In GCJ and other implementations where arrays may not + // move we might consider, at least when offset==0: + // return new DirectByteBufferImpl(array, + // address_of_data(array) + offset, + // length, length, 0, false); + // This may be more efficient, mainly because we can then use the + // same logic for all ByteBuffers. + return new ByteBufferImpl (array, 0, array.length, offset + length, offset, -1, false); } @@ -116,11 +116,10 @@ public abstract class ByteBuffer extends Buffer */ public ByteBuffer get (byte[] dst, int offset, int length) { - if ((offset < 0) - || (offset > dst.length) - || (length < 0) - || (length > (dst.length - offset))) + if (offset < 0 || length < 0 || offset + length > dst.length) throw new IndexOutOfBoundsException (); + if (length > remaining()) + throw new BufferUnderflowException(); for (int i = offset; i < offset + length; i++) { |