mirror of
https://github.com/corda/corda.git
synced 2025-06-16 14:18:20 +00:00
add constructor to ByteBuffer
This commit is contained in:
@ -16,18 +16,22 @@ public class ByteBuffer extends Buffer implements Comparable<ByteBuffer> {
|
|||||||
private final boolean readOnly;
|
private final boolean readOnly;
|
||||||
|
|
||||||
public static ByteBuffer allocate(int capacity) {
|
public static ByteBuffer allocate(int capacity) {
|
||||||
return new ByteBuffer(new byte[capacity], false);
|
return new ByteBuffer(new byte[capacity], 0, capacity, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ByteBuffer wrap(byte[] array) {
|
public static ByteBuffer wrap(byte[] array) {
|
||||||
return new ByteBuffer(array, false);
|
return wrap(array, 0, array.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteBuffer(byte[] array, boolean readOnly) {
|
public static ByteBuffer wrap(byte[] array, int offset, int length) {
|
||||||
|
return new ByteBuffer(array, offset, length, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ByteBuffer(byte[] array, int offset, int length, boolean readOnly) {
|
||||||
this.array = array;
|
this.array = array;
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
arrayOffset = 0;
|
arrayOffset = offset;
|
||||||
capacity = array.length;
|
capacity = length;
|
||||||
limit = capacity;
|
limit = capacity;
|
||||||
position = 0;
|
position = 0;
|
||||||
}
|
}
|
||||||
@ -53,12 +57,7 @@ public class ByteBuffer extends Buffer implements Comparable<ByteBuffer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer slice() {
|
public ByteBuffer slice() {
|
||||||
ByteBuffer buf = new ByteBuffer(array, true);
|
return new ByteBuffer(array, arrayOffset + position, remaining(), true);
|
||||||
buf.arrayOffset = arrayOffset + position;
|
|
||||||
buf.position = 0;
|
|
||||||
buf.capacity = remaining();
|
|
||||||
buf.limit = buf.capacity;
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int arrayOffset() {
|
public int arrayOffset() {
|
||||||
|
Reference in New Issue
Block a user