Index: D:/clear/ClearDev/nio/src/main/java/java/nio/CharArrayBuffer.java =================================================================== --- D:/clear/ClearDev/nio/src/main/java/java/nio/CharArrayBuffer.java (revision 371951) +++ D:/clear/ClearDev/nio/src/main/java/java/nio/CharArrayBuffer.java (working copy) @@ -63,6 +63,18 @@ return backingArray[offset + index]; } + public final CharBuffer get(char[] 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; } @@ -72,12 +84,10 @@ } public final CharSequence subSequence(int start, int end) { - if (start < 0 || start > remaining()) { - throw new IndexOutOfBoundsException(); - } - if (end < start || end > remaining()) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || end < start || end > remaining()) { + throw new IndexOutOfBoundsException(); + } + CharBuffer result = duplicate(); result.limit(position + end); result.position(position + start); Index: D:/clear/ClearDev/nio/src/main/java/java/nio/CharBuffer.java =================================================================== --- D:/clear/ClearDev/nio/src/main/java/java/nio/CharBuffer.java (revision 371951) +++ D:/clear/ClearDev/nio/src/main/java/java/nio/CharBuffer.java (working copy) @@ -91,12 +91,9 @@ * invalid */ public static CharBuffer wrap(char[] 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(); + } CharBuffer buf = BufferFactory.newCharBuffer(array); buf.position = start; @@ -142,12 +139,10 @@ * invalid */ public static CharBuffer wrap(CharSequence chseq, int start, int end) { - if (start < 0 || start > chseq.length()) { - throw new IndexOutOfBoundsException(); - } - if (end < start || end > chseq.length()) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || end < start || end > chseq.length()) { + throw new IndexOutOfBoundsException(); + } + CharBuffer result = BufferFactory.newCharBuffer(chseq); result.position = start; result.limit = end; @@ -382,12 +377,10 @@ * remaining() */ public CharBuffer get(char[] 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(); } @@ -555,12 +548,10 @@ * If no changes may be made to the contents of this buffer */ public CharBuffer put(char[] 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(); } @@ -593,9 +584,10 @@ if (src.remaining() > remaining()) { throw new BufferOverflowException(); } - while (src.hasRemaining()) { - put(src.get()); - } + + char[] contents = new char[src.remaining()]; + src.get(contents); + put(contents); return this; } @@ -662,12 +654,10 @@ * If no changes may be made to the contents of this buffer */ public CharBuffer put(String str, int start, int end) { - if (start < 0 || start > str.length()) { - throw new IndexOutOfBoundsException(); - } - if (end < start || end > str.length()) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || end < start || end > str.length()) { + throw new IndexOutOfBoundsException(); + } + if (end - start > remaining()) { throw new BufferOverflowException(); } Index: D:/clear/ClearDev/nio/src/main/java/java/nio/CharSequenceAdapter.java =================================================================== --- D:/clear/ClearDev/nio/src/main/java/java/nio/CharSequenceAdapter.java (revision 371951) +++ D:/clear/ClearDev/nio/src/main/java/java/nio/CharSequenceAdapter.java (working copy) @@ -70,6 +70,19 @@ return sequence.charAt(index); } + public final CharBuffer get(char[] dest, int off, int len) { + if ((off < 0 ) || (len < 0) || off + len > dest.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferUnderflowException(); + } + int newPosition = position + len; + sequence.toString().getChars(position, newPosition, dest, off); + position = newPosition; + return this; + } + public boolean isDirect() { return false; } @@ -115,12 +128,10 @@ } public CharSequence subSequence(int start, int end) { - if (start < 0 || start > remaining()) { - throw new IndexOutOfBoundsException(); - } - if (end < start || end > remaining()) { - throw new IndexOutOfBoundsException(); - } + if (end < start || start < 0 || end > remaining()) { + throw new IndexOutOfBoundsException(); + } + CharSequenceAdapter result = copy(this); result.position = position + start; result.limit = position + end; Index: D:/clear/ClearDev/nio/src/main/java/java/nio/CharToByteBufferAdapter.java =================================================================== --- D:/clear/ClearDev/nio/src/main/java/java/nio/CharToByteBufferAdapter.java (revision 371951) +++ D:/clear/ClearDev/nio/src/main/java/java/nio/CharToByteBufferAdapter.java (working copy) @@ -139,12 +139,10 @@ } public CharSequence subSequence(int start, int end) { - if (start < 0 || start > remaining()) { - throw new IndexOutOfBoundsException(); - } - if (end < start || end > remaining()) { - throw new IndexOutOfBoundsException(); - } + if (start < 0 || end < start || end > remaining()) { + throw new IndexOutOfBoundsException(); + } + CharBuffer result = duplicate(); result.limit(position + end); result.position(position + start); Index: D:/clear/ClearDev/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java =================================================================== --- D:/clear/ClearDev/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java (revision 371951) +++ D:/clear/ClearDev/nio/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java (working copy) @@ -80,6 +80,14 @@ throw new ReadOnlyBufferException(); } + public final CharBuffer put(char[] src, int off, int len) { + throw new ReadOnlyBufferException(); + } + + public CharBuffer put(String src, int start, int end) { + throw new ReadOnlyBufferException(); + } + public CharBuffer slice() { return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset + position); Index: D:/clear/ClearDev/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java =================================================================== --- D:/clear/ClearDev/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java (revision 371951) +++ D:/clear/ClearDev/nio/src/main/java/java/nio/ReadWriteCharArrayBuffer.java (working copy) @@ -100,6 +100,18 @@ return this; } + public CharBuffer put(char[] src, int off, int len) { + if (off < 0 || len < 0 || len + off > src.length) { + throw new IndexOutOfBoundsException(); + } + if (len > remaining()) { + throw new BufferOverflowException(); + } + System.arraycopy(src, off, backingArray, offset+position, len); + position += len; + return this; + } + public CharBuffer slice() { return new ReadWriteCharArrayBuffer(remaining(), backingArray, offset + position);