mirror of
https://github.com/corda/corda.git
synced 2025-06-14 13:18:18 +00:00
added get/put float/double to ByteBuffers, as well as duplicate
This commit is contained in:
@ -14,10 +14,9 @@ public abstract class ByteBuffer
|
||||
extends Buffer
|
||||
implements Comparable<ByteBuffer>
|
||||
{
|
||||
private final boolean readOnly;
|
||||
|
||||
protected ByteBuffer(boolean readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
this.readonly = readOnly;
|
||||
}
|
||||
|
||||
public static ByteBuffer allocate(int capacity) {
|
||||
@ -39,6 +38,8 @@ public abstract class ByteBuffer
|
||||
public abstract ByteBuffer asReadOnlyBuffer();
|
||||
|
||||
public abstract ByteBuffer slice();
|
||||
|
||||
public abstract ByteBuffer duplicate();
|
||||
|
||||
protected abstract void doPut(int offset, byte val);
|
||||
|
||||
@ -122,7 +123,7 @@ public abstract class ByteBuffer
|
||||
public ByteBuffer put(byte[] arr) {
|
||||
return put(arr, 0, arr.length);
|
||||
}
|
||||
|
||||
|
||||
private void rawPutLong(int position, long val) {
|
||||
doPut(position , (byte) ((val >> 56) & 0xff));
|
||||
doPut(position + 1, (byte) ((val >> 48) & 0xff));
|
||||
@ -145,6 +146,14 @@ public abstract class ByteBuffer
|
||||
doPut(position , (byte) ((val >> 8) & 0xff));
|
||||
doPut(position + 1, (byte) ((val ) & 0xff));
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble(int position, double val) {
|
||||
return putLong(position, Double.doubleToRawLongBits(val));
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat(int position, float val) {
|
||||
return putInt(position, Float.floatToRawIntBits(val));
|
||||
}
|
||||
|
||||
public ByteBuffer putLong(int position, long val) {
|
||||
checkPut(position, 8, true);
|
||||
@ -169,6 +178,14 @@ public abstract class ByteBuffer
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble(double val) {
|
||||
return putLong(Double.doubleToRawLongBits(val));
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat(float val) {
|
||||
return putInt(Float.floatToRawIntBits(val));
|
||||
}
|
||||
|
||||
public ByteBuffer putLong(long val) {
|
||||
checkPut(position, 8, false);
|
||||
@ -207,6 +224,14 @@ public abstract class ByteBuffer
|
||||
public ByteBuffer get(byte[] dst) {
|
||||
return get(dst, 0, dst.length);
|
||||
}
|
||||
|
||||
public double getDouble(int position) {
|
||||
return Double.longBitsToDouble(getLong(position));
|
||||
}
|
||||
|
||||
public float getFloat(int position) {
|
||||
return Float.intBitsToFloat(getInt(position));
|
||||
}
|
||||
|
||||
public long getLong(int position) {
|
||||
checkGet(position, 8, true);
|
||||
@ -248,7 +273,15 @@ public abstract class ByteBuffer
|
||||
return (short) (( ((int) (doGet(position ) & 0xFF)) << 8)
|
||||
| (((int) (doGet(position + 1) & 0xFF)) ));
|
||||
}
|
||||
|
||||
|
||||
public double getDouble() {
|
||||
return Double.longBitsToDouble(getLong());
|
||||
}
|
||||
|
||||
public float getFloat() {
|
||||
return Float.intBitsToFloat(getInt());
|
||||
}
|
||||
|
||||
public long getLong() {
|
||||
checkGet(position, 8, false);
|
||||
|
||||
@ -274,7 +307,7 @@ public abstract class ByteBuffer
|
||||
}
|
||||
|
||||
protected void checkPut(int position, int amount, boolean absolute) {
|
||||
if (readOnly) {
|
||||
if (isReadOnly()) {
|
||||
throw new ReadOnlyBufferException();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user