fix a couple of ByteBuffer regressions

The compact() and put(ByteBuffer) methods regressed as of the recent
refactoring to support direct byte buffers.
This commit is contained in:
Joel Dice
2012-09-14 11:40:26 -06:00
parent 3a5abaf58a
commit 2d9bbec214
2 changed files with 11 additions and 4 deletions

View File

@ -31,6 +31,10 @@ class ArrayByteBuffer extends ByteBuffer {
return b; return b;
} }
public boolean hasArray() {
return true;
}
public byte[] array() { public byte[] array() {
return array; return array;
} }
@ -49,9 +53,10 @@ class ArrayByteBuffer extends ByteBuffer {
} }
public ByteBuffer put(ByteBuffer src) { public ByteBuffer put(ByteBuffer src) {
checkPut(position, src.remaining()); int length = src.remaining();
src.get(array, arrayOffset + position, src.remaining()); checkPut(position, length);
position += src.remaining(); src.get(array, arrayOffset + position, length);
position += length;
return this; return this;
} }

View File

@ -53,13 +53,15 @@ public abstract class ByteBuffer
} }
public ByteBuffer compact() { public ByteBuffer compact() {
int remaining = remaining();
if (position != 0) { if (position != 0) {
ByteBuffer b = slice(); ByteBuffer b = slice();
position = 0; position = 0;
put(b); put(b);
} }
position = remaining(); position = remaining;
limit(capacity()); limit(capacity());
return this; return this;