implement asReadOnlyBuffer and getShort(int) in ByteBuffer

This commit is contained in:
Joel Dice 2011-09-29 18:25:03 -06:00
parent 61457dca70
commit 84bcbbcaa3

View File

@ -36,6 +36,13 @@ public class ByteBuffer extends Buffer implements Comparable<ByteBuffer> {
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<ByteBuffer> {
| ((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;