From 2d9bbec214280af9d95ec5c16141cba3ace5002f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 14 Sep 2012 11:40:26 -0600 Subject: [PATCH] fix a couple of ByteBuffer regressions The compact() and put(ByteBuffer) methods regressed as of the recent refactoring to support direct byte buffers. --- classpath/java/nio/ArrayByteBuffer.java | 11 ++++++++--- classpath/java/nio/ByteBuffer.java | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/classpath/java/nio/ArrayByteBuffer.java b/classpath/java/nio/ArrayByteBuffer.java index 2f2e7d5024..336945c1bb 100644 --- a/classpath/java/nio/ArrayByteBuffer.java +++ b/classpath/java/nio/ArrayByteBuffer.java @@ -31,6 +31,10 @@ class ArrayByteBuffer extends ByteBuffer { return b; } + public boolean hasArray() { + return true; + } + public byte[] array() { return array; } @@ -49,9 +53,10 @@ class ArrayByteBuffer extends ByteBuffer { } public ByteBuffer put(ByteBuffer src) { - checkPut(position, src.remaining()); - src.get(array, arrayOffset + position, src.remaining()); - position += src.remaining(); + int length = src.remaining(); + checkPut(position, length); + src.get(array, arrayOffset + position, length); + position += length; return this; } diff --git a/classpath/java/nio/ByteBuffer.java b/classpath/java/nio/ByteBuffer.java index 47eec8c1dc..3a6548d2b3 100644 --- a/classpath/java/nio/ByteBuffer.java +++ b/classpath/java/nio/ByteBuffer.java @@ -53,13 +53,15 @@ public abstract class ByteBuffer } public ByteBuffer compact() { + int remaining = remaining(); + if (position != 0) { ByteBuffer b = slice(); position = 0; put(b); } - position = remaining(); + position = remaining; limit(capacity()); return this;