ByteBufUtil

A collection of utility methods that is related with handling {@link ByteBuf}, such as the generation of hex dump and swapping an integer's byte order.

Members

Static functions

compare
int compare(ByteBuf bufferA, ByteBuf bufferB)

Compares the two specified buffers as described in {@link ByteBuf#compareTo(ByteBuf)}. This method is useful when implementing a new buffer type.

decodeString
string decodeString(ByteBuf src, int readerIndex, int len, Charset charset)

Encode the given {@link CharBuffer} using the given {@link Charset} into a new {@link ByteBuf} which is allocated via the {@link ByteBufAllocator}.

ensureWritableSuccess
bool ensureWritableSuccess(int ensureWritableResult)

Used to determine if the return value of {@link ByteBuf#ensureWritable(int, bool)} means that there is adequate space and a write operation will succeed. @param ensureWritableResult The return value from {@link ByteBuf#ensureWritable(int, bool)}. @return {@code true} if {@code ensureWritableResult} means that there is adequate space and a write operation will succeed.

equals
bool equals(ByteBuf a, int aStartIndex, ByteBuf b, int bStartIndex, int length)

Returns {@code true} if and only if the two specified buffers are identical to each other for {@code length} bytes starting at {@code aStartIndex} index for the {@code a} buffer and {@code bStartIndex} index for the {@code b} buffer. A more compact way to express this is: <p> {@code a[aStartIndex : aStartIndex + length] == b[bStartIndex : bStartIndex + length]}

equals
bool equals(ByteBuf bufferA, ByteBuf bufferB)

Returns {@code true} if and only if the two specified buffers are identical to each other as described in {@link ByteBuf#equals(Object)}. This method is useful when implementing a new buffer type.

getBytes
byte[] getBytes(ByteBuf buf)

Create a copy of the underlying storage from {@code buf} into a byte array. The copy will start at {@link ByteBuf#readerIndex()} and copy {@link ByteBuf#readableBytes()} bytes.

getBytes
byte[] getBytes(ByteBuf buf, int start, int length)

Create a copy of the underlying storage from {@code buf} into a byte array. The copy will start at {@code start} and copy {@code length} bytes.

getBytes
byte[] getBytes(ByteBuf buf, int start, int length, bool copy)

Return an array of the underlying storage from {@code buf} into a byte array. The copy will start at {@code start} and copy {@code length} bytes. If {@code copy} is true a copy will be made of the memory. If {@code copy} is false the underlying storage will be shared, if possible.

hexDump
string hexDump(ByteBuf buffer)

Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> of the specified buffer's readable bytes.

hexDump
string hexDump(ByteBuf buffer, int fromIndex, int length)

Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> of the specified buffer's sub-region.

hexDump
string hexDump(byte[] array)

Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> of the specified byte array.

hexDump
string hexDump(byte[] array, size_t fromIndex, size_t length)

Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a> of the specified byte array's sub-region.

indexOf
int indexOf(ByteBuf needle, ByteBuf haystack)

Returns the reader index of needle in haystack, or -1 if needle is not in haystack.

indexOf
int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value)

The default implementation of {@link ByteBuf#indexOf(int, int, byte)}. This method is useful when implementing a new buffer type.

readBytes
ByteBuf readBytes(ByteBufAllocator alloc, ByteBuf buffer, int length)

Read the given amount of bytes into a new {@link ByteBuf} that is allocated from the {@link ByteBufAllocator}.

swapInt
int swapInt(int value)

Toggles the endianness of the specified 32-bit integer.

swapLong
long swapLong(long value)

Toggles the endianness of the specified 64-bit long integer.

swapMedium
int swapMedium(int value)

Toggles the endianness of the specified 24-bit medium integer.

swapShort
short swapShort(short value)

Toggles the endianness of the specified 16-bit short integer.

threadLocalTempArray
byte[] threadLocalTempArray(int minLength)

Allocates a new array if minLength > {@link ByteBufUtil#MAX_TL_ARRAY_LEN}

toHash
int toHash(ByteBuf buffer)

Calculates the hash code of the specified buffer. This method is useful when implementing a new buffer type.

Static variables

DEFAULT_ALLOCATOR
ByteBufAllocator DEFAULT_ALLOCATOR;
Undocumented in source.

Variables

MAX_TL_ARRAY_LEN
enum int MAX_TL_ARRAY_LEN;
Undocumented in source.
WRITE_CHUNK_SIZE
enum int WRITE_CHUNK_SIZE;
Undocumented in source.

Meta