|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.hazelcast.client.impl.protocol.util.UnsafeBuffer
public class UnsafeBuffer
Supports regular, byte ordered, and atomic (memory ordered) access to an underlying buffer.
The buffer can be a byte[] or one of the various ByteBuffer
implementations.
Field Summary | |
---|---|
static Charset |
UTF_8
UTF-8 charset |
Constructor Summary | |
---|---|
UnsafeBuffer(byte[] buffer)
Attach a view to a byte[] for providing direct access. |
|
UnsafeBuffer(byte[] buffer,
int offset,
int length)
Attach a view to a byte[] for providing direct access. |
|
UnsafeBuffer(ByteBuffer buffer)
Attach a view to a ByteBuffer for providing direct access, the ByteBuffer can be
heap based or direct. |
|
UnsafeBuffer(ByteBuffer buffer,
int offset,
int length)
Attach a view to a ByteBuffer for providing direct access, the ByteBuffer can be
heap based or direct. |
|
UnsafeBuffer(DirectBuffer buffer)
Attach a view to an existing DirectBuffer . |
|
UnsafeBuffer(DirectBuffer buffer,
int offset,
int length)
Attach a view to an existing DirectBuffer . |
|
UnsafeBuffer(long address,
int length)
Attach a view to an off-heap memory region by address. |
Method Summary | |
---|---|
void |
addIntOrdered(int index,
int increment)
Add a value to a given index with ordered store semantics. |
void |
addLongOrdered(int index,
long increment)
Add a value to a given index with ordered store semantics. |
long |
addressOffset()
Reads the underlying offset to to the memory address. |
void |
boundsCheck(int index,
int length)
Check that a given length of bytes is within the bounds from a given index. |
byte[] |
byteArray()
Get the underlying byte[] if one exists. |
ByteBuffer |
byteBuffer()
Get the underlying ByteBuffer if one exists. |
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. |
boolean |
compareAndSetInt(int index,
int expectedValue,
int updateValue)
Atomic compare and set of a int given an expected value. |
boolean |
compareAndSetLong(int index,
long expectedValue,
long updateValue)
Performs an atomic compare and set of a long, given an expected value. |
byte |
getByte(int index)
Get the value at a given index. |
void |
getBytes(int index,
byte[] dst)
Get from the underlying buffer into a supplied byte array. |
void |
getBytes(int index,
byte[] dst,
int offset,
int length)
Get bytes from the underlying buffer into a supplied byte array. |
void |
getBytes(int index,
ByteBuffer dstBuffer,
int length)
Get from the underlying buffer into a supplied ByteBuffer . |
void |
getBytes(int index,
MutableDirectBuffer dstBuffer,
int dstIndex,
int length)
Get bytes from this DirectBuffer into the provided MutableDirectBuffer at given indices. |
double |
getDouble(int index)
Get the value at a given index. |
double |
getDouble(int index,
ByteOrder byteOrder)
Get the value at a given index. |
float |
getFloat(int index)
Get the value at a given index. |
float |
getFloat(int index,
ByteOrder byteOrder)
Get the value at a given index. |
int |
getInt(int index)
Get the value at a given index. |
int |
getInt(int index,
ByteOrder byteOrder)
Get the value at a given index. |
int |
getIntVolatile(int index)
Get the value at a given index with volatile semantics. |
long |
getLong(int index)
Get the value at a given index. |
long |
getLong(int index,
ByteOrder byteOrder)
Get the value at a given index. |
long |
getLongVolatile(int index)
Get the value at a given index with volatile semantics. |
short |
getShort(int index)
Get the value at a given index. |
short |
getShort(int index,
ByteOrder byteOrder)
Get the value at a given index. |
short |
getShortVolatile(int index)
Get the value at a given index with volatile semantics. |
String |
getStringUtf8(int offset,
ByteOrder byteOrder)
Get a String from bytes encoded in UTF-8 format that is length prefixed. |
String |
getStringUtf8(int offset,
int length)
Get part of String from bytes encoded in UTF-8 format that is length prefixed. |
String |
getStringWithoutLengthUtf8(int offset,
int length)
Get an encoded UTF-8 String from the buffer that does not have a length prefix. |
void |
putByte(int index,
byte value)
Put a value to a given index. |
void |
putBytes(int index,
byte[] src)
Put an array of src into the underlying buffer. |
void |
putBytes(int index,
byte[] src,
int offset,
int length)
Put an array into the underlying buffer. |
void |
putBytes(int index,
ByteBuffer srcBuffer,
int length)
Put bytes into the underlying buffer for the view. |
void |
putBytes(int index,
ByteBuffer srcBuffer,
int srcIndex,
int length)
Put bytes into the underlying buffer for the view. |
void |
putBytes(int index,
DirectBuffer srcBuffer,
int srcIndex,
int length)
Put bytes from a source DirectBuffer into this MutableDirectBuffer at given indices. |
void |
putDouble(int index,
double value)
Put a value to a given index. |
void |
putDouble(int index,
double value,
ByteOrder byteOrder)
Put a value to a given index. |
void |
putFloat(int index,
float value)
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)
Put a value to a given index. |
void |
putInt(int index,
int value,
ByteOrder byteOrder)
Put a value at a given index. |
void |
putIntOrdered(int index,
int value)
Put a value to a given index with ordered semantics. |
void |
putIntVolatile(int index,
int value)
Put a value to a given index with volatile semantics. |
void |
putLong(int index,
long value)
Put a value at a given index. |
void |
putLong(int index,
long value,
ByteOrder byteOrder)
Put a value at a given index. |
void |
putLongOrdered(int index,
long value)
Put a value to a given index with ordered store semantics. |
void |
putLongVolatile(int index,
long value)
Put a value to a given index with volatile semantics. |
void |
putShort(int index,
short value)
Put a value to a given index. |
void |
putShort(int index,
short value,
ByteOrder byteOrder)
Put a value to a given index. |
void |
putShortVolatile(int index,
short value)
Put a value to a given index with volatile semantics. |
int |
putStringUtf8(int offset,
String value,
ByteOrder byteOrder)
Encode a String as UTF-8 bytes to the buffer with a length prefix. |
int |
putStringUtf8(int offset,
String value,
ByteOrder byteOrder,
int maxEncodedSize)
Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check. |
int |
putStringWithoutLengthUtf8(int offset,
String value)
Encode a String as UTF-8 bytes in the buffer without a length prefix. |
void |
setMemory(int index,
int length,
byte value)
Set a region of memory to a given byte value. |
void |
wrap(byte[] buffer)
Attach a view to a byte[] for providing direct access. |
void |
wrap(byte[] buffer,
int offset,
int length)
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(ByteBuffer buffer,
int offset,
int length)
Attach a view to a ByteBuffer for providing direct access. |
void |
wrap(DirectBuffer buffer)
Attach a view to an existing DirectBuffer |
void |
wrap(DirectBuffer buffer,
int offset,
int length)
Attach a view to a DirectBuffer for providing direct access. |
void |
wrap(long address,
int length)
Attach a view to an off-heap memory region by address. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Charset UTF_8
Constructor Detail |
---|
public UnsafeBuffer(byte[] buffer)
buffer
- The buffer to which the view is attached.public UnsafeBuffer(byte[] buffer, int offset, int length)
buffer
- The buffer to which the view is attached.offset
- The offest within the buffer to begin the view.length
- The length of the buffer to be included.public UnsafeBuffer(ByteBuffer buffer)
ByteBuffer
for providing direct access, the ByteBuffer
can be
heap based or direct.
buffer
- The buffer to which the view is attached.public UnsafeBuffer(ByteBuffer buffer, int offset, int length)
ByteBuffer
for providing direct access, the ByteBuffer
can be
heap based or direct.
buffer
- The buffer to which the view is attached.offset
- The offset within the buffer to begin the attach.length
- The length of the buffer to be included in the attach.public UnsafeBuffer(DirectBuffer buffer)
DirectBuffer
.
buffer
- The buffer to which the view is attached.public UnsafeBuffer(DirectBuffer buffer, int offset, int length)
DirectBuffer
.
buffer
- The buffer to which the view is attached.offset
- The offset within the buffer to begin the attach.length
- The length of the view to be included in the attach.public UnsafeBuffer(long address, int length)
address
- The address where the off-heap memory region begins.length
- The length of the view to be included in the attach.Method Detail |
---|
public void wrap(byte[] buffer)
DirectBuffer
wrap
in interface DirectBuffer
buffer
- to which the view is attached.public void wrap(byte[] buffer, int offset, int length)
DirectBuffer
wrap
in interface DirectBuffer
buffer
- to which the view is attached.offset
- at which the view begins.length
- of the buffer included in the viewpublic void wrap(ByteBuffer buffer)
DirectBuffer
ByteBuffer
for providing direct access, the ByteBuffer
can be
heap based or direct.
wrap
in interface DirectBuffer
buffer
- to which the view is attached.public void wrap(ByteBuffer buffer, int offset, int length)
DirectBuffer
ByteBuffer
for providing direct access.
wrap
in interface DirectBuffer
buffer
- to which the view is attached.offset
- at which the view begins.length
- of the buffer included in the viewpublic void wrap(DirectBuffer buffer)
DirectBuffer
DirectBuffer
wrap
in interface DirectBuffer
buffer
- to which the view is attached.public void wrap(DirectBuffer buffer, int offset, int length)
DirectBuffer
DirectBuffer
for providing direct access.
wrap
in interface DirectBuffer
buffer
- to which the view is attached.offset
- at which the view begins.length
- of the buffer included in the viewpublic void wrap(long address, int length)
DirectBuffer
wrap
in interface DirectBuffer
address
- where the memory begins off-heaplength
- of the buffer from the given addresspublic long addressOffset()
DirectBuffer
addressOffset
in interface DirectBuffer
public byte[] byteArray()
DirectBuffer
byteArray
in interface DirectBuffer
public ByteBuffer byteBuffer()
DirectBuffer
ByteBuffer
if one exists.
byteBuffer
in interface DirectBuffer
ByteBuffer
if one exists.public void setMemory(int index, int length, byte value)
MutableDirectBuffer
setMemory
in interface MutableDirectBuffer
index
- The index at which to start the memory region.length
- The length of the run of bytes to set in the memory region.value
- The value of the byte that is set in the memory region.public int capacity()
DirectBuffer
capacity
in interface DirectBuffer
public void checkLimit(int limit)
DirectBuffer
checkLimit
in interface DirectBuffer
limit
- up to which access is required.public long getLong(int index, ByteOrder byteOrder)
DirectBuffer
getLong
in interface DirectBuffer
index
- in bytes from which to get.byteOrder
- of the value to be read.
public void putLong(int index, long value, ByteOrder byteOrder)
MutableDirectBuffer
putLong
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value to put at the given index.byteOrder
- The byteOrder of the value when written.public long getLong(int index)
DirectBuffer
getLong
in interface DirectBuffer
index
- in bytes from which to get.
public void putLong(int index, long value)
MutableDirectBuffer
putLong
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public long getLongVolatile(int index)
AtomicBuffer
getLongVolatile
in interface AtomicBuffer
index
- The index in bytes from where to get the value.
public void putLongVolatile(int index, long value)
AtomicBuffer
putLongVolatile
in interface AtomicBuffer
index
- The index in bytes for where to put the value.value
- The value to put at the given index.public void putLongOrdered(int index, long value)
AtomicBuffer
putLongOrdered
in interface AtomicBuffer
index
- The index in bytes for where to put the value.value
- The value to put at the given index.public void addLongOrdered(int index, long increment)
AtomicBuffer
addLongOrdered
in interface AtomicBuffer
index
- The index in bytes for where to increment or decrement the value.increment
- The increment or decrement by which the value at the index will be adjusted.public boolean compareAndSetLong(int index, long expectedValue, long updateValue)
AtomicBuffer
compareAndSetLong
in interface AtomicBuffer
index
- The index in bytes for where to put the value.expectedValue
- at to be compared The expected value that is compared to the value at the index.updateValue
- The value to be exchanged with the value at the index.
public int getInt(int index, ByteOrder byteOrder)
DirectBuffer
getInt
in interface DirectBuffer
index
- in bytes from which to get.byteOrder
- of the value to be read.
public void putInt(int index, int value, ByteOrder byteOrder)
MutableDirectBuffer
putInt
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.byteOrder
- The byteOrder of the value when written.public int getInt(int index)
DirectBuffer
getInt
in interface DirectBuffer
index
- in bytes from which to get.
public void putInt(int index, int value)
MutableDirectBuffer
putInt
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public int getIntVolatile(int index)
AtomicBuffer
getIntVolatile
in interface AtomicBuffer
index
- The index in bytes from where to get the value.
public void putIntVolatile(int index, int value)
AtomicBuffer
putIntVolatile
in interface AtomicBuffer
index
- The index in bytes for where to put the value.value
- The value to put at the given index.public void putIntOrdered(int index, int value)
AtomicBuffer
putIntOrdered
in interface AtomicBuffer
index
- The index in bytes for where to put the value.value
- The value to put at the given index.public void addIntOrdered(int index, int increment)
AtomicBuffer
addIntOrdered
in interface AtomicBuffer
index
- The index in bytes for where to put the value.increment
- by which the value at the index will be adjusted.public boolean compareAndSetInt(int index, int expectedValue, int updateValue)
AtomicBuffer
compareAndSetInt
in interface AtomicBuffer
index
- The index in bytes for where to put the value.expectedValue
- at to be compared The expected value that is compared to the value at the index.updateValue
- The value to be exchanged with the value at the index.
public double getDouble(int index, ByteOrder byteOrder)
DirectBuffer
getDouble
in interface DirectBuffer
index
- in bytes from which to get.byteOrder
- of the value to be read.
public void putDouble(int index, double value, ByteOrder byteOrder)
MutableDirectBuffer
putDouble
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.byteOrder
- The byteOrder of the value when written.public double getDouble(int index)
DirectBuffer
getDouble
in interface DirectBuffer
index
- in bytes from which to get.
public void putDouble(int index, double value)
MutableDirectBuffer
putDouble
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public float getFloat(int index, ByteOrder byteOrder)
DirectBuffer
getFloat
in interface DirectBuffer
index
- in bytes from which to get.byteOrder
- of the value to be read.
public void putFloat(int index, float value, ByteOrder byteOrder)
MutableDirectBuffer
putFloat
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.byteOrder
- of the value when written.public float getFloat(int index)
DirectBuffer
getFloat
in interface DirectBuffer
index
- in bytes from which to get.
public void putFloat(int index, float value)
MutableDirectBuffer
putFloat
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public short getShort(int index, ByteOrder byteOrder)
DirectBuffer
getShort
in interface DirectBuffer
index
- in bytes from which to get.byteOrder
- of the value to be read.
public void putShort(int index, short value, ByteOrder byteOrder)
MutableDirectBuffer
putShort
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.byteOrder
- of the value when written.public short getShort(int index)
DirectBuffer
getShort
in interface DirectBuffer
index
- in bytes from which to get.
public void putShort(int index, short value)
MutableDirectBuffer
putShort
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public short getShortVolatile(int index)
AtomicBuffer
getShortVolatile
in interface AtomicBuffer
index
- The index in bytes from where to get the value.
public void putShortVolatile(int index, short value)
AtomicBuffer
putShortVolatile
in interface AtomicBuffer
index
- The index in bytes for where to put the value.value
- The value to put at the given index.public byte getByte(int index)
DirectBuffer
getByte
in interface DirectBuffer
index
- in bytes from which to get.
public void putByte(int index, byte value)
MutableDirectBuffer
putByte
in interface MutableDirectBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public void getBytes(int index, byte[] dst)
DirectBuffer
getBytes
in interface DirectBuffer
index
- in the underlying buffer to start from.dst
- into which the dst will be copied.public void getBytes(int index, byte[] dst, int offset, int length)
DirectBuffer
getBytes
in interface DirectBuffer
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 void getBytes(int index, MutableDirectBuffer dstBuffer, int dstIndex, int length)
DirectBuffer
DirectBuffer
into the provided MutableDirectBuffer
at given indices.
getBytes
in interface DirectBuffer
index
- in this buffer to begin getting the bytes.dstBuffer
- to which the bytes will be copied.dstIndex
- in the channel buffer to which the byte copy will begin.length
- of the bytes to be copied.public void getBytes(int index, ByteBuffer dstBuffer, int length)
DirectBuffer
ByteBuffer
.
getBytes
in interface DirectBuffer
index
- in the underlying buffer to start from.dstBuffer
- into which the bytes will be copied.length
- of the supplied buffer to use.public void putBytes(int index, byte[] src)
MutableDirectBuffer
putBytes
in interface MutableDirectBuffer
index
- The index in the underlying buffer from which to start the array.src
- The array to be copied into the underlying buffer.public void putBytes(int index, byte[] src, int offset, int length)
MutableDirectBuffer
putBytes
in interface MutableDirectBuffer
index
- The index in the underlying buffer from which to start the array.src
- The array to be copied into the underlying buffer.offset
- The offset in the supplied buffer at which to begin the copy.length
- The length of the supplied buffer to copy.public void putBytes(int index, ByteBuffer srcBuffer, int length)
MutableDirectBuffer
Buffer.position()
to Buffer.limit()
.
putBytes
in interface MutableDirectBuffer
index
- The index in the underlying buffer from which to start the array.srcBuffer
- The source buffer to copy the bytes from.length
- The length of the supplied buffer to copy.public void putBytes(int index, ByteBuffer srcBuffer, int srcIndex, int length)
MutableDirectBuffer
putBytes
in interface MutableDirectBuffer
index
- The index in the underlying buffer from which to start the array.srcBuffer
- The source buffer to copy the bytes from (does not change position).srcIndex
- The index in the source buffer from which the copy will begin.length
- The length in bytes to be copied.public void putBytes(int index, DirectBuffer srcBuffer, int srcIndex, int length)
MutableDirectBuffer
DirectBuffer
into this MutableDirectBuffer
at given indices.
putBytes
in interface MutableDirectBuffer
index
- The index in this buffer from which to begin putting the bytes.srcBuffer
- The source buffer from which the bytes will be copied.srcIndex
- The index in the source buffer from which the byte copy will begin.length
- The length in bytes to be copied.public String getStringUtf8(int offset, ByteOrder byteOrder)
DirectBuffer
getStringUtf8
in interface DirectBuffer
offset
- at which the String begins.byteOrder
- for the length at the beginning of the String.
public String getStringUtf8(int offset, int length)
DirectBuffer
getStringUtf8
in interface DirectBuffer
offset
- at which the String begins.length
- of the String in bytes to decode.
public int putStringUtf8(int offset, String value, ByteOrder byteOrder)
MutableDirectBuffer
putStringUtf8
in interface MutableDirectBuffer
offset
- The offset at which the String should be encoded.value
- The value of the String to be encoded.byteOrder
- The byteOrder for the length prefix.
public int putStringUtf8(int offset, String value, ByteOrder byteOrder, int maxEncodedSize)
MutableDirectBuffer
putStringUtf8
in interface MutableDirectBuffer
offset
- The offset at which the String should be encoded.value
- The value of the String to be encoded.byteOrder
- The byteOrder for the length prefix.maxEncodedSize
- The maximum encoded size to be checked before writing to the buffer.
public String getStringWithoutLengthUtf8(int offset, int length)
DirectBuffer
getStringWithoutLengthUtf8
in interface DirectBuffer
offset
- at which the String begins.length
- of the String in bytes to decode.
public int putStringWithoutLengthUtf8(int offset, String value)
MutableDirectBuffer
putStringWithoutLengthUtf8
in interface MutableDirectBuffer
offset
- The offset at which the String begins.value
- The value of the String to be encoded.
public void boundsCheck(int index, int length)
DirectBuffer
boundsCheck
in interface DirectBuffer
index
- from which to check.length
- in bytes of the range to check.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |