harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r372498 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java: com/ibm/platform/struct/ java/nio/
Date Thu, 26 Jan 2006 10:23:33 GMT
Author: tellison
Date: Thu Jan 26 02:23:13 2006
New Revision: 372498

URL: http://svn.apache.org/viewcvs?rev=372498&view=rev
Log:
Applying NIO buffer performance enhancements, described in HARMONY-43

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/PlatformAddress.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/PlatformAddress.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/PlatformAddress.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/PlatformAddress.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/PlatformAddress.java Thu Jan 26 02:23:13 2006
@@ -118,6 +118,16 @@
 		return PlatformAddress.on(addr);
 	}
 
+    public void setByteArray(int offset, byte[] bytes, int bytesOffset, int length) {
+		memorySpy.rangeCheck(this, offset, length * SIZEOF_JBYTE);
+		osMemory.setByteArray(osaddr + offset, bytes, bytesOffset, length);
+	}
+
+	public void getByteArray(int offset, byte[] bytes, int bytesOffset, int length) {
+		memorySpy.rangeCheck(this, offset, length * SIZEOF_JBYTE);
+		osMemory.getByteArray(osaddr + offset, bytes, bytesOffset, length);
+	}
+    
 	public void setByte(int offset, byte value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JBYTE);
 		osMemory.setByte(osaddr + offset, value);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -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 @@
 	 *                <code>remaining()</code>
 	 */
 	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;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -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;
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DoubleBuffer.java Thu Jan 26 02:23:13 2006
@@ -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 @@
 	 *                <code>remaining()</code>
 	 */
 	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;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/FloatBuffer.java Thu Jan 26 02:23:13 2006
@@ -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 @@
 	 *                <code>remaining()</code>
 	 */
 	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;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/HeapByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);
-	}
-
-	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);
+        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);
+        }
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/IntBuffer.java Thu Jan 26 02:23:13 2006
@@ -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 @@
 	 *                <code>remaining()</code>
 	 */
 	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;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/LongBuffer.java Thu Jan 26 02:23:13 2006
@@ -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 @@
 	 *                <code>remaining()</code>
 	 */
 	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;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -15,7 +15,7 @@
 
 package java.nio;
 
-
+import com.ibm.platform.struct.PlatformAddress;
 
 /**
  * DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
@@ -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();
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -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();
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDirectByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -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) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteHeapByteBuffer.java Thu Jan 26 02:23:13 2006
@@ -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));
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteIntArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteLongArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ReadWriteShortArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortArrayBuffer.java Thu Jan 26 02:23:13 2006
@@ -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;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java?rev=372498&r1=372497&r2=372498&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/ShortBuffer.java Thu Jan 26 02:23:13 2006
@@ -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 @@
 	 *                <code>remaining()</code>
 	 */
 	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;
 	}
 



Mime
View raw message