com.hazelcast.client.impl.protocol.util
Class UnsafeBuffer

java.lang.Object
  extended by com.hazelcast.client.impl.protocol.util.UnsafeBuffer
All Implemented Interfaces:
AtomicBuffer, DirectBuffer, MutableDirectBuffer

public class UnsafeBuffer
extends Object
implements AtomicBuffer

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

UTF_8

public static final Charset UTF_8
UTF-8 charset

Constructor Detail

UnsafeBuffer

public UnsafeBuffer(byte[] buffer)
Attach a view to a byte[] for providing direct access.

Parameters:
buffer - The buffer to which the view is attached.

UnsafeBuffer

public UnsafeBuffer(byte[] buffer,
                    int offset,
                    int length)
Attach a view to a byte[] for providing direct access.

Parameters:
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.

UnsafeBuffer

public UnsafeBuffer(ByteBuffer buffer)
Attach a view to a ByteBuffer for providing direct access, the ByteBuffer can be heap based or direct.

Parameters:
buffer - The buffer to which the view is attached.

UnsafeBuffer

public 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.

Parameters:
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.

UnsafeBuffer

public UnsafeBuffer(DirectBuffer buffer)
Attach a view to an existing DirectBuffer.

Parameters:
buffer - The buffer to which the view is attached.

UnsafeBuffer

public UnsafeBuffer(DirectBuffer buffer,
                    int offset,
                    int length)
Attach a view to an existing DirectBuffer.

Parameters:
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.

UnsafeBuffer

public UnsafeBuffer(long address,
                    int length)
Attach a view to an off-heap memory region by address.

Parameters:
address - The address where the off-heap memory region begins.
length - The length of the view to be included in the attach.
Method Detail

wrap

public void wrap(byte[] buffer)
Description copied from interface: DirectBuffer
Attach a view to a byte[] for providing direct access.

Specified by:
wrap in interface DirectBuffer
Parameters:
buffer - to which the view is attached.

wrap

public void wrap(byte[] buffer,
                 int offset,
                 int length)
Description copied from interface: DirectBuffer
Attach a view to a byte[] for providing direct access.

Specified by:
wrap in interface DirectBuffer
Parameters:
buffer - to which the view is attached.
offset - at which the view begins.
length - of the buffer included in the view

wrap

public void wrap(ByteBuffer buffer)
Description copied from interface: DirectBuffer
Attach a view to a ByteBuffer for providing direct access, the ByteBuffer can be heap based or direct.

Specified by:
wrap in interface DirectBuffer
Parameters:
buffer - to which the view is attached.

wrap

public void wrap(ByteBuffer buffer,
                 int offset,
                 int length)
Description copied from interface: DirectBuffer
Attach a view to a ByteBuffer for providing direct access.

Specified by:
wrap in interface DirectBuffer
Parameters:
buffer - to which the view is attached.
offset - at which the view begins.
length - of the buffer included in the view

wrap

public void wrap(DirectBuffer buffer)
Description copied from interface: DirectBuffer
Attach a view to an existing DirectBuffer

Specified by:
wrap in interface DirectBuffer
Parameters:
buffer - to which the view is attached.

wrap

public void wrap(DirectBuffer buffer,
                 int offset,
                 int length)
Description copied from interface: DirectBuffer
Attach a view to a DirectBuffer for providing direct access.

Specified by:
wrap in interface DirectBuffer
Parameters:
buffer - to which the view is attached.
offset - at which the view begins.
length - of the buffer included in the view

wrap

public void wrap(long address,
                 int length)
Description copied from interface: DirectBuffer
Attach a view to an off-heap memory region by address.

Specified by:
wrap in interface DirectBuffer
Parameters:
address - where the memory begins off-heap
length - of the buffer from the given address

addressOffset

public long addressOffset()
Description copied from interface: DirectBuffer
Reads the underlying offset to to the memory address.

Specified by:
addressOffset in interface DirectBuffer
Returns:
the underlying offset to to the memory address.

byteArray

public byte[] byteArray()
Description copied from interface: DirectBuffer
Get the underlying byte[] if one exists.

Specified by:
byteArray in interface DirectBuffer
Returns:
the underlying byte[] if one exists.

byteBuffer

public ByteBuffer byteBuffer()
Description copied from interface: DirectBuffer
Get the underlying ByteBuffer if one exists.

Specified by:
byteBuffer in interface DirectBuffer
Returns:
the underlying ByteBuffer if one exists.

setMemory

public void setMemory(int index,
                      int length,
                      byte value)
Description copied from interface: MutableDirectBuffer
Set a region of memory to a given byte value.

Specified by:
setMemory in interface MutableDirectBuffer
Parameters:
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.

capacity

public int capacity()
Description copied from interface: DirectBuffer
Get the capacity of the underlying buffer.

Specified by:
capacity in interface DirectBuffer
Returns:
the capacity of the underlying buffer in bytes.

checkLimit

public void checkLimit(int limit)
Description copied from interface: DirectBuffer
Check that a given limit is not greater than the capacity of a buffer from a given offset.

Can be overridden in a DirectBuffer subclass to enable an extensible buffer or handle retry after a flush.

Specified by:
checkLimit in interface DirectBuffer
Parameters:
limit - up to which access is required.

getLong

public long getLong(int index,
                    ByteOrder byteOrder)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getLong in interface DirectBuffer
Parameters:
index - in bytes from which to get.
byteOrder - of the value to be read.
Returns:
the value for at a given index

putLong

public void putLong(int index,
                    long value,
                    ByteOrder byteOrder)
Description copied from interface: MutableDirectBuffer
Put a value at a given index.

Specified by:
putLong in interface MutableDirectBuffer
Parameters:
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.

getLong

public long getLong(int index)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getLong in interface DirectBuffer
Parameters:
index - in bytes from which to get.
Returns:
the value for at a given index

putLong

public void putLong(int index,
                    long value)
Description copied from interface: MutableDirectBuffer
Put a value at a given index.

Specified by:
putLong in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.

getLongVolatile

public long getLongVolatile(int index)
Description copied from interface: AtomicBuffer
Get the value at a given index with volatile semantics.

Specified by:
getLongVolatile in interface AtomicBuffer
Parameters:
index - The index in bytes from where to get the value.
Returns:
The value retrieved from the given index.

putLongVolatile

public void putLongVolatile(int index,
                            long value)
Description copied from interface: AtomicBuffer
Put a value to a given index with volatile semantics.

Specified by:
putLongVolatile in interface AtomicBuffer
Parameters:
index - The index in bytes for where to put the value.
value - The value to put at the given index.

putLongOrdered

public void putLongOrdered(int index,
                           long value)
Description copied from interface: AtomicBuffer
Put a value to a given index with ordered store semantics.

Specified by:
putLongOrdered in interface AtomicBuffer
Parameters:
index - The index in bytes for where to put the value.
value - The value to put at the given index.

addLongOrdered

public void addLongOrdered(int index,
                           long increment)
Description copied from interface: AtomicBuffer
Add a value to a given index with ordered store semantics. Use a negative increment to decrement.

Specified by:
addLongOrdered in interface AtomicBuffer
Parameters:
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.

compareAndSetLong

public boolean compareAndSetLong(int index,
                                 long expectedValue,
                                 long updateValue)
Description copied from interface: AtomicBuffer
Performs an atomic compare and set of a long, given an expected value.

Specified by:
compareAndSetLong in interface AtomicBuffer
Parameters:
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.
Returns:
true if the compare and put were successful, false otherwise.

getInt

public int getInt(int index,
                  ByteOrder byteOrder)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getInt in interface DirectBuffer
Parameters:
index - in bytes from which to get.
byteOrder - of the value to be read.
Returns:
the value at a given index.

putInt

public void putInt(int index,
                   int value,
                   ByteOrder byteOrder)
Description copied from interface: MutableDirectBuffer
Put a value at a given index.

Specified by:
putInt in interface MutableDirectBuffer
Parameters:
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.

getInt

public int getInt(int index)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getInt in interface DirectBuffer
Parameters:
index - in bytes from which to get.
Returns:
the value for at a given index

putInt

public void putInt(int index,
                   int value)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putInt in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.

getIntVolatile

public int getIntVolatile(int index)
Description copied from interface: AtomicBuffer
Get the value at a given index with volatile semantics.

Specified by:
getIntVolatile in interface AtomicBuffer
Parameters:
index - The index in bytes from where to get the value.
Returns:
The value retrieved from the given index.

putIntVolatile

public void putIntVolatile(int index,
                           int value)
Description copied from interface: AtomicBuffer
Put a value to a given index with volatile semantics.

Specified by:
putIntVolatile in interface AtomicBuffer
Parameters:
index - The index in bytes for where to put the value.
value - The value to put at the given index.

putIntOrdered

public void putIntOrdered(int index,
                          int value)
Description copied from interface: AtomicBuffer
Put a value to a given index with ordered semantics.

Specified by:
putIntOrdered in interface AtomicBuffer
Parameters:
index - The index in bytes for where to put the value.
value - The value to put at the given index.

addIntOrdered

public void addIntOrdered(int index,
                          int increment)
Description copied from interface: AtomicBuffer
Add a value to a given index with ordered store semantics. Use a negative increment to decrement.

Specified by:
addIntOrdered in interface AtomicBuffer
Parameters:
index - The index in bytes for where to put the value.
increment - by which the value at the index will be adjusted.

compareAndSetInt

public boolean compareAndSetInt(int index,
                                int expectedValue,
                                int updateValue)
Description copied from interface: AtomicBuffer
Atomic compare and set of a int given an expected value.

Specified by:
compareAndSetInt in interface AtomicBuffer
Parameters:
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.
Returns:
true if the compare and put were successful, false otherwise.

getDouble

public double getDouble(int index,
                        ByteOrder byteOrder)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getDouble in interface DirectBuffer
Parameters:
index - in bytes from which to get.
byteOrder - of the value to be read.
Returns:
the value at a given index.

putDouble

public void putDouble(int index,
                      double value,
                      ByteOrder byteOrder)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putDouble in interface MutableDirectBuffer
Parameters:
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.

getDouble

public double getDouble(int index)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getDouble in interface DirectBuffer
Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

putDouble

public void putDouble(int index,
                      double value)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putDouble in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.

getFloat

public float getFloat(int index,
                      ByteOrder byteOrder)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getFloat in interface DirectBuffer
Parameters:
index - in bytes from which to get.
byteOrder - of the value to be read.
Returns:
the value at a given index.

putFloat

public void putFloat(int index,
                     float value,
                     ByteOrder byteOrder)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putFloat in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.
byteOrder - of the value when written.

getFloat

public float getFloat(int index)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getFloat in interface DirectBuffer
Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

putFloat

public void putFloat(int index,
                     float value)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putFloat in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.

getShort

public short getShort(int index,
                      ByteOrder byteOrder)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getShort in interface DirectBuffer
Parameters:
index - in bytes from which to get.
byteOrder - of the value to be read.
Returns:
the value at a given index.

putShort

public void putShort(int index,
                     short value,
                     ByteOrder byteOrder)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putShort in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.
byteOrder - of the value when written.

getShort

public short getShort(int index)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getShort in interface DirectBuffer
Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

putShort

public void putShort(int index,
                     short value)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putShort in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.

getShortVolatile

public short getShortVolatile(int index)
Description copied from interface: AtomicBuffer
Get the value at a given index with volatile semantics.

Specified by:
getShortVolatile in interface AtomicBuffer
Parameters:
index - The index in bytes from where to get the value.
Returns:
The value retrieved from the given index.

putShortVolatile

public void putShortVolatile(int index,
                             short value)
Description copied from interface: AtomicBuffer
Put a value to a given index with volatile semantics.

Specified by:
putShortVolatile in interface AtomicBuffer
Parameters:
index - The index in bytes for where to put the value.
value - The value to put at the given index.

getByte

public byte getByte(int index)
Description copied from interface: DirectBuffer
Get the value at a given index.

Specified by:
getByte in interface DirectBuffer
Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

putByte

public void putByte(int index,
                    byte value)
Description copied from interface: MutableDirectBuffer
Put a value to a given index.

Specified by:
putByte in interface MutableDirectBuffer
Parameters:
index - The index in bytes where the value is put.
value - The value put at the given index.

getBytes

public void getBytes(int index,
                     byte[] dst)
Description copied from interface: DirectBuffer
Get from the underlying buffer into a supplied byte array. This method will try to fill the supplied byte array.

Specified by:
getBytes in interface DirectBuffer
Parameters:
index - in the underlying buffer to start from.
dst - into which the dst will be copied.

getBytes

public void getBytes(int index,
                     byte[] dst,
                     int offset,
                     int length)
Description copied from interface: DirectBuffer
Get bytes from the underlying buffer into a supplied byte array.

Specified by:
getBytes in interface DirectBuffer
Parameters:
index - in the underlying buffer to start from.
dst - into which the bytes will be copied.
offset - in the supplied buffer to start the copy
length - of the supplied buffer to use.

getBytes

public void getBytes(int index,
                     MutableDirectBuffer dstBuffer,
                     int dstIndex,
                     int length)
Description copied from interface: DirectBuffer
Get bytes from this DirectBuffer into the provided MutableDirectBuffer at given indices.

Specified by:
getBytes in interface DirectBuffer
Parameters:
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.

getBytes

public void getBytes(int index,
                     ByteBuffer dstBuffer,
                     int length)
Description copied from interface: DirectBuffer
Get from the underlying buffer into a supplied ByteBuffer.

Specified by:
getBytes in interface DirectBuffer
Parameters:
index - in the underlying buffer to start from.
dstBuffer - into which the bytes will be copied.
length - of the supplied buffer to use.

putBytes

public void putBytes(int index,
                     byte[] src)
Description copied from interface: MutableDirectBuffer
Put an array of src into the underlying buffer.

Specified by:
putBytes in interface MutableDirectBuffer
Parameters:
index - The index in the underlying buffer from which to start the array.
src - The array to be copied into the underlying buffer.

putBytes

public void putBytes(int index,
                     byte[] src,
                     int offset,
                     int length)
Description copied from interface: MutableDirectBuffer
Put an array into the underlying buffer.

Specified by:
putBytes in interface MutableDirectBuffer
Parameters:
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.

putBytes

public void putBytes(int index,
                     ByteBuffer srcBuffer,
                     int length)
Description copied from interface: MutableDirectBuffer
Put bytes into the underlying buffer for the view. Bytes will be copied from current Buffer.position() to Buffer.limit().

Specified by:
putBytes in interface MutableDirectBuffer
Parameters:
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.

putBytes

public void putBytes(int index,
                     ByteBuffer srcBuffer,
                     int srcIndex,
                     int length)
Description copied from interface: MutableDirectBuffer
Put bytes into the underlying buffer for the view. Bytes will be copied from the buffer index to the buffer index + length.

Specified by:
putBytes in interface MutableDirectBuffer
Parameters:
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.

putBytes

public void putBytes(int index,
                     DirectBuffer srcBuffer,
                     int srcIndex,
                     int length)
Description copied from interface: MutableDirectBuffer
Put bytes from a source DirectBuffer into this MutableDirectBuffer at given indices.

Specified by:
putBytes in interface MutableDirectBuffer
Parameters:
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.

getStringUtf8

public String getStringUtf8(int offset,
                            ByteOrder byteOrder)
Description copied from interface: DirectBuffer
Get a String from bytes encoded in UTF-8 format that is length prefixed.

Specified by:
getStringUtf8 in interface DirectBuffer
Parameters:
offset - at which the String begins.
byteOrder - for the length at the beginning of the String.
Returns:
the String as represented by the UTF-8 encoded bytes.

getStringUtf8

public String getStringUtf8(int offset,
                            int length)
Description copied from interface: DirectBuffer
Get part of String from bytes encoded in UTF-8 format that is length prefixed.

Specified by:
getStringUtf8 in interface DirectBuffer
Parameters:
offset - at which the String begins.
length - of the String in bytes to decode.
Returns:
the String as represented by the UTF-8 encoded bytes.

putStringUtf8

public int putStringUtf8(int offset,
                         String value,
                         ByteOrder byteOrder)
Description copied from interface: MutableDirectBuffer
Encode a String as UTF-8 bytes to the buffer with a length prefix.

Specified by:
putStringUtf8 in interface MutableDirectBuffer
Parameters:
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.
Returns:
The number of bytes put to the buffer.

putStringUtf8

public int putStringUtf8(int offset,
                         String value,
                         ByteOrder byteOrder,
                         int maxEncodedSize)
Description copied from interface: MutableDirectBuffer
Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.

Specified by:
putStringUtf8 in interface MutableDirectBuffer
Parameters:
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.
Returns:
The number of bytes put to the buffer.

getStringWithoutLengthUtf8

public String getStringWithoutLengthUtf8(int offset,
                                         int length)
Description copied from interface: DirectBuffer
Get an encoded UTF-8 String from the buffer that does not have a length prefix.

Specified by:
getStringWithoutLengthUtf8 in interface DirectBuffer
Parameters:
offset - at which the String begins.
length - of the String in bytes to decode.
Returns:
the String as represented by the UTF-8 encoded bytes.

putStringWithoutLengthUtf8

public int putStringWithoutLengthUtf8(int offset,
                                      String value)
Description copied from interface: MutableDirectBuffer
Encode a String as UTF-8 bytes in the buffer without a length prefix.

Specified by:
putStringWithoutLengthUtf8 in interface MutableDirectBuffer
Parameters:
offset - The offset at which the String begins.
value - The value of the String to be encoded.
Returns:
The number of bytes encoded.

boundsCheck

public void boundsCheck(int index,
                        int length)
Description copied from interface: DirectBuffer
Check that a given length of bytes is within the bounds from a given index.

Specified by:
boundsCheck in interface DirectBuffer
Parameters:
index - from which to check.
length - in bytes of the range to check.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.