Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java (working copy) @@ -52,6 +52,11 @@ super(address, capacity, offset); } + ReadWriteDirectByteBuffer(PlatformAddress address, int aCapacity, + int anOffset) { + super(new SafeAddress(address), aCapacity, anOffset); + } + public ByteBuffer asReadOnlyBuffer() { return ReadOnlyDirectByteBuffer.copy(this, mark); } @@ -74,18 +79,6 @@ return false; } - protected byte[] protectedArray() { - throw new UnsupportedOperationException(); - } - - protected int protectedArrayOffset() { - throw new UnsupportedOperationException(); - } - - protected boolean protectedHasArray() { - return false; - } - public ByteBuffer put(byte value) { if (position == limit) { throw new BufferOverflowException(); @@ -100,9 +93,31 @@ } getBaseAddress().setByte(offset + index, value); return this; - } + /* + * Override ByteBuffer.put(byte[], int, int) to improve performance. + * + * (non-Javadoc) + * + * @see java.nio.ByteBuffer#put(byte[], int, int) + */ + public ByteBuffer put(byte[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + if (isReadOnly()) { + throw new ReadOnlyBufferException(); + } + getBaseAddress().setByteArray(offset + position, src, off, + len); + position += len; + return this; + } + public ByteBuffer putDouble(double value) { int newPosition = position + 8; if (newPosition > limit) { Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java (working copy) @@ -100,6 +100,19 @@ return this; } + public LongBuffer put(long[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + System.arraycopy(src, off, backingArray, offset + + position, len); + position += len; + return this; + } + public LongBuffer slice() { return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java (working copy) @@ -101,6 +101,29 @@ return this; } + /* + * Override ByteBuffer.put(byte[], int, int) to improve performance. + * + * (non-Javadoc) + * + * @see java.nio.ByteBuffer#put(byte[], int, int) + */ + public ByteBuffer put(byte[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + if (isReadOnly()) { + throw new ReadOnlyBufferException(); + } + System.arraycopy(src, off, backingArray, offset + + position, len); + position += len; + return this; + } + public ByteBuffer putDouble(double value) { return putLong(Double.doubleToRawLongBits(value)); } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DoubleArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DoubleArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DoubleArrayBuffer.java (working copy) @@ -63,6 +63,19 @@ return backingArray[offset + index]; } + public final DoubleBuffer get(double[] dest, int off, int len) { + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + System.arraycopy(backingArray, offset + position, dest, + off, len); + position += len; + return this; + } + public final boolean isDirect() { return false; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java (working copy) @@ -80,6 +80,10 @@ throw new ReadOnlyBufferException(); } + public final IntBuffer put(int[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public IntBuffer slice() { return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/IntBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/IntBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/IntBuffer.java (working copy) @@ -85,12 +85,9 @@ * invalid */ public static IntBuffer wrap(int[] array, int start, int len) { - if (start < 0 || start > array.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || start + len > array.length) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || len < 0 || len + start > array.length) { + throw new IndexOutOfBoundsException(); + } IntBuffer buf = BufferFactory.newIntBuffer(array); buf.position = start; @@ -307,12 +304,9 @@ * remaining() */ public IntBuffer get(int[] dest, int off, int len) { - if (off < 0 || off > dest.length) { - throw new IndexOutOfBoundsException(); - } - if ((len < 0) || off + len > dest.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || len + off > dest.length) { + throw new IndexOutOfBoundsException(); + } if (len > remaining()) { throw new BufferUnderflowException(); } @@ -467,12 +461,10 @@ * If no changes may be made to the contents of this buffer */ public IntBuffer put(int[] src, int off, int len) { - if (off < 0 || off > src.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || off + len > src.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || len + off > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferOverflowException(); } @@ -505,9 +497,9 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + int[] contents = new int[src.remaining()]; + src.get(contents); + put(contents); return this; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java (working copy) @@ -15,8 +15,8 @@ package java.nio; +import com.ibm.platform.struct.PlatformAddress; - /** * DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer * compose the implementation of platform memory based byte buffers. @@ -46,6 +46,11 @@ super(address, capacity, offset); } + protected ReadOnlyDirectByteBuffer(PlatformAddress address, int capacity, + int offset) { + super(new SafeAddress(address), capacity, offset); + } + public ByteBuffer asReadOnlyBuffer() { return copy(this, mark); } @@ -58,18 +63,6 @@ return copy(this, mark); } - protected byte[] protectedArray() { - throw new UnsupportedOperationException(); - } - - protected int protectedArrayOffset() { - throw new UnsupportedOperationException(); - } - - protected boolean protectedHasArray() { - return false; - } - public boolean isReadOnly() { return true; } @@ -82,6 +75,10 @@ throw new ReadOnlyBufferException(); } + public ByteBuffer put(byte[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public ByteBuffer putDouble(double value) { throw new ReadOnlyBufferException(); } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/LongArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/LongArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/LongArrayBuffer.java (working copy) @@ -63,6 +63,18 @@ return backingArray[offset + index]; } + public final LongBuffer get(long[] dest, int off, int len) { + if (off < 0 || len < 0 || len + off > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + System.arraycopy(backingArray, offset+position, dest, off, len); + position += len; + return this; + } + public final boolean isDirect() { return false; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ShortArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ShortArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ShortArrayBuffer.java (working copy) @@ -63,6 +63,19 @@ return backingArray[offset + index]; } + public final ShortBuffer get(short[] dest, int off, int len) { + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + System.arraycopy(backingArray, offset + position, dest, + off, len); + position += len; + return this; + } + public final boolean isDirect() { return false; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/LongBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/LongBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/LongBuffer.java (working copy) @@ -86,12 +86,9 @@ * invalid */ public static LongBuffer wrap(long[] array, int start, int len) { - if (start < 0 || start > array.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || start + len > array.length) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || len < 0 || len + start > array.length) { + throw new IndexOutOfBoundsException(); + } LongBuffer buf = BufferFactory.newLongBuffer(array); buf.position = start; @@ -308,12 +305,10 @@ * remaining() */ public LongBuffer get(long[] dest, int off, int len) { - if (off < 0 || off > dest.length) { - throw new IndexOutOfBoundsException(); - } - if ((len < 0) || off + len > dest.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || len + off > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferUnderflowException(); } @@ -474,12 +469,10 @@ * If no changes may be made to the contents of this buffer */ public LongBuffer put(long[] src, int off, int len) { - if (off < 0 || off > src.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || off + len > src.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || len + off > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferOverflowException(); } @@ -512,9 +505,9 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + long[] contents = new long[src.remaining()]; + src.get(contents); + put(contents); return this; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java (working copy) @@ -81,6 +81,10 @@ throw new ReadOnlyBufferException(); } + public ByteBuffer put(byte[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public ByteBuffer putDouble(double value) { throw new ReadOnlyBufferException(); } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ShortBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ShortBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ShortBuffer.java (working copy) @@ -86,12 +86,9 @@ * invalid */ public static ShortBuffer wrap(short[] array, int start, int len) { - if (start < 0 || start > array.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || start + len > array.length) { - throw new IndexOutOfBoundsException(); - } + if (start< 0 || len < 0 || start + len > array.length) { + throw new IndexOutOfBoundsException(); + } ShortBuffer buf = BufferFactory.newShortBuffer(array); buf.position = start; @@ -308,12 +305,9 @@ * remaining() */ public ShortBuffer get(short[] dest, int off, int len) { - if (off < 0 || off > dest.length) { - throw new IndexOutOfBoundsException(); - } - if ((len < 0) || off + len > dest.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } if (len > remaining()) { throw new BufferUnderflowException(); } @@ -472,12 +466,10 @@ * If no changes may be made to the contents of this buffer */ public ShortBuffer put(short[] src, int off, int len) { - if (off < 0 || off > src.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || off + len > src.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferOverflowException(); } @@ -510,9 +502,9 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + short[] contents = new short[src.remaining()]; + src.get(contents); + put(contents); return this; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ByteBuffer.java (working copy) @@ -101,12 +101,9 @@ * invalid */ public static ByteBuffer wrap(byte[] array, int start, int len) { - if (start < 0 || start > array.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || start + len > array.length) { - throw new IndexOutOfBoundsException(); - } + if ((start< 0 ) || (len < 0) || start+ len > array.length) { + throw new IndexOutOfBoundsException(); + } ByteBuffer buf = BufferFactory.newByteBuffer(array); buf.position = start; @@ -428,12 +425,10 @@ * remaining() */ public ByteBuffer get(byte[] dest, int off, int len) { - if (off < 0 || off > dest.length) { - throw new IndexOutOfBoundsException(); - } - if ((len < 0) || off + len > dest.length) { - throw new IndexOutOfBoundsException(); - } + if ((off < 0 ) || (len < 0) || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferUnderflowException(); } @@ -787,12 +782,10 @@ * If no changes may be made to the contents of this buffer */ public ByteBuffer put(byte[] src, int off, int len) { - if (off < 0 || off > src.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || off + len > src.length) { - throw new IndexOutOfBoundsException(); - } + if ((off < 0 ) || (len < 0) || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferOverflowException(); } @@ -825,9 +818,9 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + byte[] contents = new byte[src.remaining()]; + src.get(contents); + put(contents); return this; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/FloatArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/FloatArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/FloatArrayBuffer.java (working copy) @@ -63,6 +63,18 @@ return backingArray[offset + index]; } + public final FloatBuffer get(float[] dest, int off, int len) { + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + System.arraycopy(backingArray, offset+position, dest, off, len); + position += len; + return this; + } + public final boolean isDirect() { return false; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/FloatBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/FloatBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/FloatBuffer.java (working copy) @@ -82,12 +82,9 @@ * invalid */ public static FloatBuffer wrap(float[] array, int start, int len) { - if (start < 0 || start > array.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || start + len > array.length) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || len < 0 || start + len > array.length) { + throw new IndexOutOfBoundsException(); + } FloatBuffer buf = BufferFactory.newFloatBuffer(array); buf.position = start; @@ -295,12 +292,10 @@ * remaining() */ public FloatBuffer get(float[] dest, int off, int len) { - if (off < 0 || off > dest.length) { - throw new IndexOutOfBoundsException(); - } - if ((len < 0) || off + len > dest.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferUnderflowException(); } @@ -452,12 +447,10 @@ * If no changes may be made to the contents of this buffer */ public FloatBuffer put(float[] src, int off, int len) { - if (off < 0 || off > src.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || off + len > src.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferOverflowException(); } @@ -490,9 +483,9 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + float[] contents = new float[src.remaining()]; + src.get(contents); + put(contents); return this; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java (working copy) @@ -103,6 +103,18 @@ return this; } + public ShortBuffer put(short[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + System.arraycopy(src, off, backingArray, offset+position, len); + position += len; + return this; + } + public ShortBuffer slice() { return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java (working copy) @@ -82,6 +82,10 @@ throw new ReadOnlyBufferException(); } + public final DoubleBuffer put(double[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public DoubleBuffer slice() { return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DoubleBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DoubleBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DoubleBuffer.java (working copy) @@ -83,12 +83,9 @@ * invalid */ public static DoubleBuffer wrap(double[] array, int start, int len) { - if (start < 0 || start > array.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || start + len > array.length) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || len < 0 || start+ len > array.length) { + throw new IndexOutOfBoundsException(); + } DoubleBuffer buf = BufferFactory.newDoubleBuffer(array); buf.position = start; @@ -296,12 +293,10 @@ * remaining() */ public DoubleBuffer get(double[] dest, int off, int len) { - if (off < 0 || off > dest.length) { - throw new IndexOutOfBoundsException(); - } - if ((len < 0) || off + len > dest.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferUnderflowException(); } @@ -456,12 +451,10 @@ * If no changes may be made to the contents of this buffer */ public DoubleBuffer put(double[] src, int off, int len) { - if (off < 0 || off > src.length) { - throw new IndexOutOfBoundsException(); - } - if (len < 0 || off + len > src.length) { - throw new IndexOutOfBoundsException(); - } + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { throw new BufferOverflowException(); } @@ -494,9 +487,9 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + double[] doubles = new double[src.remaining()]; + src.get(doubles); + put(doubles); return this; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java (working copy) @@ -103,6 +103,19 @@ return this; } + public FloatBuffer put(float[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + System.arraycopy(src, off, backingArray, offset + + position, len); + position += len; + return this; + } + public FloatBuffer slice() { return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java (working copy) @@ -103,6 +103,19 @@ return this; } + public DoubleBuffer put(double[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + System.arraycopy(src, off, backingArray, offset + + position, len); + position += len; + return this; + } + public DoubleBuffer slice() { return new ReadWriteDoubleArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/IntArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/IntArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/IntArrayBuffer.java (working copy) @@ -63,6 +63,18 @@ return backingArray[offset + index]; } + public final IntBuffer get(int[] dest, int off, int len) { + if (off < 0 || len < 0 || len + off > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + System.arraycopy(backingArray, offset+position, dest, off, len); + position += len; + return this; + } + public final boolean isDirect() { return false; } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java (working copy) @@ -80,6 +80,10 @@ throw new ReadOnlyBufferException(); } + public final LongBuffer put(long[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public LongBuffer slice() { return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java (working copy) @@ -80,6 +80,10 @@ throw new ReadOnlyBufferException(); } + public final ShortBuffer put(short[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public ShortBuffer slice() { return new ReadOnlyShortArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DirectByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DirectByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/DirectByteBuffer.java (working copy) @@ -36,7 +36,7 @@ // This class will help us track whether the address is valid or not. static final class SafeAddress { - protected boolean isValid = true; + protected volatile boolean isValid = true; protected final PlatformAddress address; @@ -64,6 +64,24 @@ this.offset = offset; } + /* + * Override ByteBuffer.get(byte[], int, int) to improve performance. + * + * (non-Javadoc) + * @see java.nio.ByteBuffer#get(byte[], int, int) + */ + public final ByteBuffer get(byte[] dest, int off, int len) { + if ((off < 0 ) || (len < 0) || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + getBaseAddress().getByteArray(offset+position, dest, off, len); + position += len; + return this; + } + public final byte get() { if (position == limit) { throw new BufferUnderflowException(); @@ -227,4 +245,16 @@ safeAddress.address.free(); } } + + final protected byte[] protectedArray() { + throw new UnsupportedOperationException(); + } + + final protected int protectedArrayOffset() { + throw new UnsupportedOperationException(); + } + + final protected boolean protectedHasArray() { + return false; + } } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java (working copy) @@ -100,6 +100,19 @@ return this; } + public IntBuffer put(int[] src, int off, int len) { + if (off < 0 || len < 0 || off + len > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + System.arraycopy(src, off, backingArray, offset + + position, len); + position += len; + return this; + } + public IntBuffer slice() { return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset + position); Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/HeapByteBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/HeapByteBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/HeapByteBuffer.java (working copy) @@ -55,6 +55,25 @@ } } + /* + * Override ByteBuffer.get(byte[], int, int) to improve performance. + * + * (non-Javadoc) + * + * @see java.nio.ByteBuffer#get(byte[], int, int) + */ + public final ByteBuffer get(byte[] dest, int off, int len) { + if (off < 0 || len < 0 || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + System.arraycopy(backingArray, offset + position, dest, off, len); + position += len; + return this; + } + public final byte get() { if (position == limit) { throw new BufferUnderflowException(); @@ -143,74 +162,88 @@ protected final int loadInt(int index) { int baseOffset = offset + index; int bytes = 0; - for (int i = 0; i < 4; i++) { - bytes = bytes << 8; - bytes = bytes | (backingArray[baseOffset + i] & 0xFF); - } - return (order == Endianness.BIG_ENDIAN) ? bytes : swap(bytes); + if(order == Endianness.BIG_ENDIAN){ + for (int i = 0; i < 4; i++) { + bytes = bytes << 8; + bytes = bytes | (backingArray[baseOffset + i] & 0xFF); + } + }else{ + for (int i = 3; i >= 0; i--) { + bytes = bytes << 8; + bytes = bytes | (backingArray[baseOffset + i] & 0xFF); + } + } + return bytes; } protected final long loadLong(int index) { int baseOffset = offset + index; long bytes = 0; - for (int i = 0; i < 8; i++) { - bytes = bytes << 8; - bytes = bytes | (backingArray[baseOffset + i] & 0xFF); - } - return (order == Endianness.BIG_ENDIAN) ? bytes : swap(bytes); + if(order == Endianness.BIG_ENDIAN){ + for (int i = 0; i < 8; i++) { + bytes = bytes << 8; + bytes = bytes | (backingArray[baseOffset + i] & 0xFF); + } + }else{ + for (int i = 7; i >= 0; i--) { + bytes = bytes << 8; + bytes = bytes | (backingArray[baseOffset + i] & 0xFF); + } + } + return bytes; } protected final short loadShort(int index) { int baseOffset = offset + index; - short bytes = (short) (backingArray[baseOffset] << 8); - bytes |= (backingArray[baseOffset + 1] & 0xFF); - return (order == Endianness.BIG_ENDIAN) ? bytes : swap(bytes); + short bytes = 0; + if(order == Endianness.BIG_ENDIAN){ + bytes = (short) (backingArray[baseOffset] << 8); + bytes |= (backingArray[baseOffset + 1] & 0xFF); + }else{ + bytes = (short) (backingArray[baseOffset+1] << 8); + bytes |= (backingArray[baseOffset] & 0xFF); + } + return bytes; } protected final void store(int index, int value) { int baseOffset = offset + index; - int bytes = (order == Endianness.BIG_ENDIAN) ? value : swap(value); - for (int i = 3; i >= 0; i--) { - backingArray[baseOffset + i] = (byte) (bytes & 0xFF); - bytes = bytes >> 8; - } + if (order == Endianness.BIG_ENDIAN) { + for (int i = 3; i >= 0; i--) { + backingArray[baseOffset + i] = (byte) (value & 0xFF); + value = value >> 8; + } + } else { + for (int i = 0; i <= 3; i++) { + backingArray[baseOffset + i] = (byte) (value & 0xFF); + value = value >> 8; + } + } } protected final void store(int index, long value) { int baseOffset = offset + index; - long bytes = (order == Endianness.BIG_ENDIAN) ? value : swap(value); - for (int i = 7; i >= 0; i--) { - backingArray[baseOffset + i] = (byte) (bytes & 0xFF); - bytes = bytes >> 8; - } + if (order == Endianness.BIG_ENDIAN) { + for (int i = 7; i >= 0; i--) { + backingArray[baseOffset + i] = (byte) (value & 0xFF); + value = value >> 8; + } + } else { + for (int i = 0; i <= 7; i++) { + backingArray[baseOffset + i] = (byte) (value & 0xFF); + value = value >> 8; + } + } } protected final void store(int index, short value) { int baseOffset = offset + index; - short bytes = (order == Endianness.BIG_ENDIAN) ? value : swap(value); - backingArray[baseOffset] = (byte) ((bytes >> 8) & 0xFF); - backingArray[baseOffset + 1] = (byte) (bytes & 0xFF); + if (order == Endianness.BIG_ENDIAN) { + backingArray[baseOffset] = (byte) ((value >> 8) & 0xFF); + backingArray[baseOffset + 1] = (byte) (value & 0xFF); + } else { + backingArray[baseOffset+1] = (byte) ((value >> 8) & 0xFF); + backingArray[baseOffset] = (byte) (value & 0xFF); + } } - - private int swap(int value) { - short left = (short) (value >> 16); - short right = (short) value; - int topEnd = swap(right) << 16; - int btmEnd = swap(left) & 0xFFFF; - return topEnd | btmEnd; - } - - private long swap(long value) { - int left = (int) (value >> 32); - int right = (int) value; - long topEnd = ((long) swap(right)) << 32; - long btmEnd = swap(left) & 0xFFFFFFFFL; - return topEnd | btmEnd; - } - - private short swap(short value) { - int topEnd = value << 8; - int btmEnd = (value >> 8) & 0xFF; - return (short) (topEnd | btmEnd); - } } Index: D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java =================================================================== --- D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java (revision 372245) +++ D:/harmony/HarmonyDev/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java (working copy) @@ -80,6 +80,10 @@ throw new ReadOnlyBufferException(); } + public final FloatBuffer put(float[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + public FloatBuffer slice() { return new ReadOnlyFloatArrayBuffer(remaining(), backingArray, offset + position);