public class DirectBuffer extends Object
ByteBuffer that is heap or direct allocated
for direct access with native types.| Constructor and Description |
|---|
DirectBuffer(byte[] buffer)
Attach a view to a byte[] for providing direct access.
|
DirectBuffer(ByteBuffer buffer)
Attach a view to a
ByteBuffer for providing direct access, the ByteBuffer can be
heap based or direct. |
DirectBuffer(long address,
int capacity)
Attach a view to an off-heap memory region by address.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
Return the underlying byte[] for this buffer or null if none is attached.
|
ByteBuffer |
byteBuffer()
Return the underlying
ByteBuffer if one is attached. |
int |
capacity()
Get the capacity of the underlying buffer.
|
void |
checkLimit(int limit)
Check that a given limit is not greater than the capacity of a buffer from a given offset.
|
ByteBuffer |
duplicateByteBuffer()
Create a duplicate
ByteBuffer for the view in native byte order. |
byte |
getByte(int index)
Get the value at a given index.
|
int |
getBytes(int index,
byte[] dst)
Get from the underlying buffer into a supplied byte array.
|
int |
getBytes(int index,
byte[] dst,
int offset,
int length)
Get bytes from the underlying buffer into a supplied byte array.
|
int |
getBytes(int index,
ByteBuffer dstBuffer,
int length)
Get from the underlying buffer into a supplied
ByteBuffer. |
int |
getBytes(int index,
DirectBuffer dst,
int offset,
int length)
Get bytes from the underlying buffer into a supplied DirectBuffer
|
double |
getDouble(int index,
ByteOrder byteOrder)
Get the value at a given index.
|
float |
getFloat(int index,
ByteOrder byteOrder)
Get the value at a given index.
|
int |
getInt(int index,
ByteOrder byteOrder)
Get the value at a given index.
|
long |
getLong(int index,
ByteOrder byteOrder)
Get the value at a given index.
|
short |
getShort(int index,
ByteOrder byteOrder)
Get the value at a given index.
|
void |
putByte(int index,
byte value)
Put a value to a given index.
|
int |
putBytes(int index,
byte[] src)
Put an array of src into the underlying buffer.
|
int |
putBytes(int index,
byte[] src,
int offset,
int length)
Put an array into the underlying buffer.
|
int |
putBytes(int index,
ByteBuffer srcBuffer,
int length)
Put an bytes into the underlying buffer for the view.
|
int |
putBytes(int index,
DirectBuffer src,
int offset,
int length)
Put bytes from a DirectBuffer into the underlying buffer.
|
void |
putDouble(int index,
double value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putFloat(int index,
float value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putInt(int index,
int value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putLong(int index,
long value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putShort(int index,
short value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
wrap(byte[] buffer)
Attach a view to a byte[] for providing direct access.
|
void |
wrap(ByteBuffer buffer)
Attach a view to a
ByteBuffer for providing direct access, the ByteBuffer can be
heap based or direct. |
void |
wrap(long address,
int capacity)
Attach a view to an off-heap memory region by address.
|
public DirectBuffer(byte[] buffer)
buffer - to which the view is attached.public DirectBuffer(ByteBuffer buffer)
ByteBuffer for providing direct access, the ByteBuffer can be
heap based or direct.buffer - to which the view is attached.public DirectBuffer(long address,
int capacity)
address - where the memory begins off-heapcapacity - of the buffer from the given addresspublic void wrap(byte[] buffer)
buffer - to which the view is attached.public void wrap(ByteBuffer buffer)
ByteBuffer for providing direct access, the ByteBuffer can be
heap based or direct.buffer - to which the view is attached.public void wrap(long address,
int capacity)
address - where the memory begins off-heapcapacity - of the buffer from the given addresspublic byte[] array()
public ByteBuffer byteBuffer()
ByteBuffer if one is attached.ByteBuffer if one is attached.public int capacity()
public void checkLimit(int limit)
limit - access is required to.IndexOutOfBoundsException - if limit is beyond buffer capacity.public ByteBuffer duplicateByteBuffer()
ByteBuffer for the view in native byte order.
The duplicate ByteBuffer shares the underlying memory so all changes are reflected.
If no ByteBuffer is attached then one will be created.ByteBufferpublic long getLong(int index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putLong(int index,
long value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given indexbyteOrder - of the value when writtenpublic int getInt(int index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putInt(int index,
int value,
ByteOrder byteOrder)
index - in bytes for where to put.value - to be writtenbyteOrder - of the value when writtenpublic double getDouble(int index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putDouble(int index,
double value,
ByteOrder byteOrder)
index - in bytes for where to put.value - to be writtenbyteOrder - of the value when written.public float getFloat(int index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putFloat(int index,
float value,
ByteOrder byteOrder)
index - in bytes for where to put.value - to be writtenbyteOrder - of the value when written.public short getShort(int index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putShort(int index,
short value,
ByteOrder byteOrder)
index - in bytes for where to put.value - to be writtenbyteOrder - of the value when written.public byte getByte(int index)
index - in bytes from which to get.public void putByte(int index,
byte value)
index - in bytes for where to put.value - to be writtenpublic int getBytes(int index,
byte[] dst)
index - in the underlying buffer to start from.dst - into which the dst will be copied.public int getBytes(int index,
byte[] dst,
int offset,
int length)
index - in the underlying buffer to start from.dst - into which the bytes will be copied.offset - in the supplied buffer to start the copylength - of the supplied buffer to use.public int getBytes(int index,
DirectBuffer dst,
int offset,
int length)
index - in the underlying buffer to start from.dst - into which the bytes will be copied.offset - in the supplied buffer to start the copylength - of the supplied buffer to use.public int getBytes(int index,
ByteBuffer dstBuffer,
int length)
ByteBuffer.index - in the underlying buffer to start from.dstBuffer - into which the bytes will be copied.length - of the supplied buffer to use.public int putBytes(int index,
byte[] src)
index - in the underlying buffer to start from.src - to be copied to the underlying buffer.public int putBytes(int index,
byte[] src,
int offset,
int length)
index - in the underlying buffer to start from.src - to be copied to the underlying buffer.offset - in the supplied buffer to begin the copy.length - of the supplied buffer to copy.public int putBytes(int index,
DirectBuffer src,
int offset,
int length)
index - in the underlying buffer to start from.src - to be copied to the underlying buffer.offset - in the supplied buffer to begin the copy.length - of the supplied buffer to copy.public int putBytes(int index,
ByteBuffer srcBuffer,
int length)
Buffer.position() to Buffer.limit().index - in the underlying buffer to start from.srcBuffer - to copy the bytes from.length - of the source buffer in bytes to copyCopyright © 2013 Real Logic Ltd. All Rights Reserved.