public class ByteBuffer extends Buffer {
byte[] array;
+ int offset;
public static ByteBuffer allocate(int i) {
if (i < 0) {
throw new IllegalArgumentException();
}
- ByteBuffer newBuffer = new ByteBuffer(i);
+ ByteBuffer newBuffer = new ByteBuffer(-1, 0, i, i, new byte[i], 0);
return newBuffer;
}
return allocate(capacity);
}
- protected ByteBuffer(int i) {
- capacity = i;
- this.clear();
- array = new byte[i];
+ ByteBuffer(int mark, int pos, int lim, int cap, byte[] hb, int offset) {
+ super(mark, pos, lim, cap);
+ this.array = hb;
+ this.offset = offset;
+ }
+
+ ByteBuffer(int mark, int pos, int lim, int cap) {
+ this(mark, pos, lim, cap, null, 0);
}
public ByteBuffer duplicate() {
- ByteBuffer copy = new ByteBuffer(capacity);
+ ByteBuffer copy = new ByteBuffer(-1, 0, capacity, capacity, new byte[capacity], 0);
copy.array = array;
return copy;
}
public ByteBuffer slice() {
int remaining = limit - position;
- ByteBuffer copy = new ByteBuffer(remaining);
+ ByteBuffer copy = new ByteBuffer(-1, 0, remaining, remaining, new byte[remaining], 0);
copy.array = array;
return copy;
}
}
public static ByteBuffer wrap(byte[] outMess) {
- ByteBuffer byteBuffer = new ByteBuffer(outMess.length);
+ ByteBuffer byteBuffer = new ByteBuffer(-1, 0, outMess.length, outMess.length, new byte[outMess.length], 0);
byteBuffer.clear();
System.arraycopy(outMess, 0 , byteBuffer.array, 0, outMess.length);
return byteBuffer;