com.hazelcast.client.impl.protocol.util
Interface DirectBuffer

All Known Subinterfaces:
AtomicBuffer, MutableDirectBuffer
All Known Implementing Classes:
UnsafeBuffer

public interface DirectBuffer

Abstraction over a range of buffer types that allows fields to be read in native typed fashion.


Method Summary
 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.
 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.
 long getLong(int index)
          Get the value at a given index.
 long getLong(int index, ByteOrder byteOrder)
          Get the value at a given index.
 short getShort(int index)
          Get the value at a given index.
 short getShort(int index, ByteOrder byteOrder)
          Get the value at a given index.
 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 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.
 

Method Detail

wrap

void wrap(byte[] buffer)
Attach a view to a byte[] for providing direct access.

Parameters:
buffer - to which the view is attached.

wrap

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

Parameters:
buffer - to which the view is attached.
offset - at which the view begins.
length - of the buffer included in the view

wrap

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

Parameters:
buffer - to which the view is attached.

wrap

void wrap(ByteBuffer buffer,
          int offset,
          int length)
Attach a view to a ByteBuffer for providing direct access.

Parameters:
buffer - to which the view is attached.
offset - at which the view begins.
length - of the buffer included in the view

wrap

void wrap(DirectBuffer buffer)
Attach a view to an existing DirectBuffer

Parameters:
buffer - to which the view is attached.

wrap

void wrap(DirectBuffer buffer,
          int offset,
          int length)
Attach a view to a DirectBuffer for providing direct access.

Parameters:
buffer - to which the view is attached.
offset - at which the view begins.
length - of the buffer included in the view

wrap

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

Parameters:
address - where the memory begins off-heap
length - of the buffer from the given address

addressOffset

long addressOffset()
Reads the underlying offset to to the memory address.

Returns:
the underlying offset to to the memory address.

byteArray

byte[] byteArray()
Get the underlying byte[] if one exists.

Returns:
the underlying byte[] if one exists.

byteBuffer

ByteBuffer byteBuffer()
Get the underlying ByteBuffer if one exists.

Returns:
the underlying ByteBuffer if one exists.

capacity

int capacity()
Get the capacity of the underlying buffer.

Returns:
the capacity of the underlying buffer in bytes.

checkLimit

void checkLimit(int limit)
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.

Parameters:
limit - up to which access is required.
Throws:
IndexOutOfBoundsException - if limit is beyond buffer capacity.

getLong

long getLong(int index,
             ByteOrder byteOrder)
Get the value at a given index.

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

getLong

long getLong(int index)
Get the value at a given index.

Parameters:
index - in bytes from which to get.
Returns:
the value for at a given index

getInt

int getInt(int index,
           ByteOrder byteOrder)
Get the value at a given index.

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

getInt

int getInt(int index)
Get the value at a given index.

Parameters:
index - in bytes from which to get.
Returns:
the value for at a given index

getDouble

double getDouble(int index,
                 ByteOrder byteOrder)
Get the value at a given index.

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

getDouble

double getDouble(int index)
Get the value at a given index.

Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

getFloat

float getFloat(int index,
               ByteOrder byteOrder)
Get the value at a given index.

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

getFloat

float getFloat(int index)
Get the value at a given index.

Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

getShort

short getShort(int index,
               ByteOrder byteOrder)
Get the value at a given index.

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

getShort

short getShort(int index)
Get the value at a given index.

Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

getByte

byte getByte(int index)
Get the value at a given index.

Parameters:
index - in bytes from which to get.
Returns:
the value at a given index.

getBytes

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

Parameters:
index - in the underlying buffer to start from.
dst - into which the dst will be copied.

getBytes

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

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

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

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

void getBytes(int index,
              ByteBuffer dstBuffer,
              int length)
Get from the underlying buffer into a supplied ByteBuffer.

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

getStringUtf8

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

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

String getStringUtf8(int offset,
                     int length)
Get part of String from bytes encoded in UTF-8 format that is length prefixed.

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.

getStringWithoutLengthUtf8

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

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.

boundsCheck

void boundsCheck(int index,
                 int length)
Check that a given length of bytes is within the bounds from a given index.

Parameters:
index - from which to check.
length - in bytes of the range to check.
Throws:
IndexOutOfBoundsException - if the length goes outside of the capacity range.


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