From 84bcbbcaa35521f67876a548d1799b167ce00a64 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 29 Sep 2011 18:25:03 -0600 Subject: [PATCH] implement asReadOnlyBuffer and getShort(int) in ByteBuffer --- classpath/java/nio/ByteBuffer.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/classpath/java/nio/ByteBuffer.java b/classpath/java/nio/ByteBuffer.java index e8191f90a3..2dee03f7d9 100644 --- a/classpath/java/nio/ByteBuffer.java +++ b/classpath/java/nio/ByteBuffer.java @@ -36,6 +36,13 @@ public class ByteBuffer extends Buffer implements Comparable { position = 0; } + public ByteBuffer asReadOnlyBuffer() { + ByteBuffer b = new ByteBuffer(array, arrayOffset, capacity, true); + b.position(position()); + b.limit(limit()); + return b; + } + public int compareTo(ByteBuffer o) { int end = (remaining() < o.remaining() ? remaining() : o.remaining()); @@ -159,6 +166,13 @@ public class ByteBuffer extends Buffer implements Comparable { | ((array[p + 3] & 0xFF)); } + public short getShort(int position) { + checkGet(position, 2); + + int p = arrayOffset + position; + return (short) (((array[p] & 0xFF) << 8) | ((array[p + 1] & 0xFF))); + } + public int getInt() { checkGet(4); int i = get() << 24;