ByteBuf

A random and sequential accessible sequence of zero or more bytes (octets). This interface provides an abstract view for one or more primitive byte arrays ({@code byte[]}) and {@linkplain ByteBuffer NIO buffers}.

<h3>Creation of a buffer</h3>

It is recommended to create a new buffer using the helper methods in {@link Unpooled} rather than calling an individual implementation's constructor.

<h3>Random Access Indexing</h3>

Just like an ordinary primitive byte array, {@link ByteBuf} uses <a href="http://en.wikipedia.org/wiki/Zero-based_numbering">zero-based indexing</a>. It means the index of the first byte is always {@code 0} and the index of the last byte is always {@link #capacity() capacity - 1}. For example, to iterate all bytes of a buffer, you can do the following, regardless of its internal implementation:

<pre> {@link ByteBuf} buffer = ...; for (int i = 0; i &lt; buffer.capacity(); i ++) { byte b = buffer.getByte(i); System.out.println((char) b); } </pre>

<h3>Sequential Access Indexing</h3>

{@link ByteBuf} provides two pointer variables to support sequential read and write operations - {@link #readerIndex() readerIndex} for a read operation and {@link #writerIndex() writerIndex} for a write operation respectively. The following diagram shows how a buffer is segmented into three areas by the two pointers:

<pre> +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | | | (CONTENT) | | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity </pre>

<h4>Readable bytes (the actual content)</h4>

This segment is where the actual data is stored. Any operation whose name starts with {@code read} or {@code skip} will get or skip the data at the current {@link #readerIndex() readerIndex} and increase it by the number of read bytes. If the argument of the read operation is also a {@link ByteBuf} and no destination index is specified, the specified buffer's {@link #writerIndex() writerIndex} is increased together. <p> If there's not enough content left, {@link IndexOutOfBoundsException} is raised. The default value of newly allocated, wrapped or copied buffer's {@link #readerIndex() readerIndex} is {@code 0}.

<pre> // Iterates the readable bytes of a buffer. {@link ByteBuf} buffer = ...; while (buffer.isReadable()) { System.out.println(buffer.readByte()); } </pre>

<h4>Writable bytes</h4>

This segment is a undefined space which needs to be filled. Any operation whose name starts with {@code write} will write the data at the current {@link #writerIndex() writerIndex} and increase it by the number of written bytes. If the argument of the write operation is also a {@link ByteBuf}, and no source index is specified, the specified buffer's {@link #readerIndex() readerIndex} is increased together. <p> If there's not enough writable bytes left, {@link IndexOutOfBoundsException} is raised. The default value of newly allocated buffer's {@link #writerIndex() writerIndex} is {@code 0}. The default value of wrapped or copied buffer's {@link #writerIndex() writerIndex} is the {@link #capacity() capacity} of the buffer.

<pre> // Fills the writable bytes of a buffer with random integers. {@link ByteBuf} buffer = ...; while (buffer.maxWritableBytes() >= 4) { buffer.writeInt(random.nextInt()); } </pre>

<h4>Discardable bytes</h4>

This segment contains the bytes which were read already by a read operation. Initially, the size of this segment is {@code 0}, but its size increases up to the {@link #writerIndex() writerIndex} as read operations are executed. The read bytes can be discarded by calling {@link #discardReadBytes()} to reclaim unused area as depicted by the following diagram:

<pre> BEFORE discardReadBytes()

+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity

More...
abstract
class ByteBuf : ReferenceCounted {}

Members

Functions

alloc
ByteBufAllocator alloc()

Returns the {@link ByteBufAllocator} which created this buffer.

array
byte[] array()

Returns the backing byte array of this buffer.

arrayOffset
int arrayOffset()

Returns the offset of the first byte within the backing byte array of this buffer.

asReadOnly
ByteBuf asReadOnly()

Returns a read-only version of this buffer.

bytesBefore
int bytesBefore(int index, int length, byte value)

Locates the first occurrence of the specified {@code value} in this buffer. The search starts from the specified {@code index} (inclusive) and lasts for the specified {@code length}. <p> This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

bytesBefore
int bytesBefore(int length, byte value)

Locates the first occurrence of the specified {@code value} in this buffer. The search starts from the current {@code readerIndex} (inclusive) and lasts for the specified {@code length}. <p> This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

bytesBefore
int bytesBefore(byte value)

Locates the first occurrence of the specified {@code value} in this buffer. The search takes place from the current {@code readerIndex} (inclusive) to the current {@code writerIndex} (exclusive). <p> This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

capacity
int capacity()

Returns the number of bytes (octets) this buffer can contain.

capacity
ByteBuf capacity(int newCapacity)

Adjusts the capacity of this buffer. If the {@code newCapacity} is less than the current capacity, the content of this buffer is truncated. If the {@code newCapacity} is greater than the current capacity, the buffer is appended with unspecified data whose length is {@code (newCapacity - currentCapacity)}.

clear
ByteBuf clear()

Sets the {@code readerIndex} and {@code writerIndex} of this buffer to {@code 0}. This method is identical to {@link #setIndex(int, int) setIndex(0, 0)}. <p> Please note that the behavior of this method is different from that of NIO buffer, which sets the {@code limit} to the {@code capacity} of the buffer.

compareTo
int compareTo(ByteBuf buffer)

Compares the content of the specified buffer to the content of this buffer. Comparison is performed in the same manner with the string comparison functions of various languages such as {@code strcmp}, {@code memcmp} and {@link string#compareTo(string)}.

copy
ByteBuf copy(int index, int length)

Returns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

copy
ByteBuf copy()

Returns a copy of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method is identical to {@code buf.copy(buf.readerIndex(), buf.readableBytes())}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

discardReadBytes
ByteBuf discardReadBytes()

Discards the bytes between the 0th index and {@code readerIndex}. It moves the bytes between {@code readerIndex} and {@code writerIndex} to the 0th index, and sets {@code readerIndex} and {@code writerIndex} to {@code 0} and {@code oldWriterIndex - oldReaderIndex} respectively. <p> Please refer to the class documentation for more detailed explanation.

discardSomeReadBytes
ByteBuf discardSomeReadBytes()

Similar to {@link ByteBuf#discardReadBytes()} except that this method might discard some, all, or none of read bytes depending on its internal implementation to reduce overall memory bandwidth consumption at the cost of potentially additional memory consumption.

duplicate
ByteBuf duplicate()

Returns a buffer which shares the whole region of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. <p> The reader and writer marks will not be duplicated. Also be aware that this method will NOT call {@link #retain()} and so the reference count will NOT be increased. @return A buffer whose readable content is equivalent to the buffer returned by {@link #slice()}. However this buffer will share the capacity of the underlying buffer, and therefore allows access to all of the underlying content if necessary.

ensureWritable
ByteBuf ensureWritable(int minWritableBytes)

Expands the buffer {@link #capacity()} to make sure the number of {@linkplain #writableBytes() writable bytes} is equal to or greater than the specified value. If there are enough writable bytes in this buffer, this method returns with no side effect.

ensureWritable
int ensureWritable(int minWritableBytes, bool force)

Expands the buffer {@link #capacity()} to make sure the number of {@linkplain #writableBytes() writable bytes} is equal to or greater than the specified value. Unlike {@link #ensureWritable(int)}, this method returns a status code.

forEachByte
int forEachByte(int index, int length, ByteProcessor processor)

Iterates over the specified area of this buffer with the specified {@code processor} in ascending order. (i.e. {@code index}, {@code (index + 1)}, .. {@code (index + length - 1)})

forEachByte
int forEachByte(ByteProcessor processor)

Iterates over the readable bytes of this buffer with the specified {@code processor} in ascending order.

forEachByteDesc
int forEachByteDesc(int index, int length, ByteProcessor processor)

Iterates over the specified area of this buffer with the specified {@code processor} in descending order. (i.e. {@code (index + length - 1)}, {@code (index + length - 2)}, ... {@code index})

forEachByteDesc
int forEachByteDesc(ByteProcessor processor)

Iterates over the readable bytes of this buffer with the specified {@code processor} in descending order.

getBoolean
bool getBoolean(int index)

Gets a bool at the specified absolute (@code index) in this buffer. This method does not modify the {@code readerIndex} or {@code writerIndex} of this buffer.

getByte
byte getByte(int index)

Gets a byte at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getBytes
ByteBuf getBytes(int index, OutputStream outStream, int length)

Transfers this buffer's data to the specified stream starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getBytes
ByteBuf getBytes(int index, ByteBuffer dst)

Transfers this buffer's data to the specified destination starting at the specified absolute {@code index} until the destination's position reaches its limit. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer while the destination's {@code position} will be increased.

getBytes
ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length)

Transfers this buffer's data to the specified destination starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getBytes
ByteBuf getBytes(int index, ByteBuf dst, int length)

Transfers this buffer's data to the specified destination starting at the specified absolute {@code index}. This method is basically same with {@link #getBytes(int, ByteBuf, int, int)}, except that this method increases the {@code writerIndex} of the destination by the number of the transferred bytes while {@link #getBytes(int, ByteBuf, int, int)} does not. This method does not modify {@code readerIndex} or {@code writerIndex} of the source buffer (i.e. {@code this}).

getBytes
ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length)

Transfers this buffer's data to the specified destination starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of both the source (i.e. {@code this}) and the destination.

getBytes
ByteBuf getBytes(int index, ByteBuf dst)

Transfers this buffer's data to the specified destination starting at the specified absolute {@code index} until the destination becomes non-writable. This method is basically same with {@link #getBytes(int, ByteBuf, int, int)}, except that this method increases the {@code writerIndex} of the destination by the number of the transferred bytes while {@link #getBytes(int, ByteBuf, int, int)} does not. This method does not modify {@code readerIndex} or {@code writerIndex} of the source buffer (i.e. {@code this}).

getBytes
ByteBuf getBytes(int index, byte[] dst)

Transfers this buffer's data to the specified destination starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer

getChar
char getChar(int index)

Gets a 2-byte UTF-16 character at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getCharSequence
CharSequence getCharSequence(int index, int length, Charset charset)

Gets a {@link CharSequence} with the given length at the given index.

getDouble
double getDouble(int index)

Gets a 64-bit floating point number at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getDoubleLE
double getDoubleLE(int index)

Gets a 64-bit floating point number at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getFloat
float getFloat(int index)

Gets a 32-bit floating point number at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getFloatLE
float getFloatLE(int index)

Gets a 32-bit floating point number at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getInt
int getInt(int index)

Gets a 32-bit integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getIntLE
int getIntLE(int index)

Gets a 32-bit integer at the specified absolute {@code index} in this buffer with Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getLong
long getLong(int index)

Gets a 64-bit long integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getLongLE
long getLongLE(int index)

Gets a 64-bit long integer at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getMedium
int getMedium(int index)

Gets a 24-bit medium integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getMediumLE
int getMediumLE(int index)

Gets a 24-bit medium integer at the specified absolute {@code index} in this buffer in the Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getReadableBytes
byte[] getReadableBytes()
Undocumented in source.
getShort
short getShort(int index)

Gets a 16-bit short integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getShortLE
short getShortLE(int index)

Gets a 16-bit short integer at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedByte
short getUnsignedByte(int index)

Gets an unsigned byte at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedInt
long getUnsignedInt(int index)

Gets an unsigned 32-bit integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedIntLE
long getUnsignedIntLE(int index)

Gets an unsigned 32-bit integer at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedMedium
int getUnsignedMedium(int index)

Gets an unsigned 24-bit medium integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedMediumLE
int getUnsignedMediumLE(int index)

Gets an unsigned 24-bit medium integer at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedShort
int getUnsignedShort(int index)

Gets an unsigned 16-bit short integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

getUnsignedShortLE
int getUnsignedShortLE(int index)

Gets an unsigned 16-bit short integer at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

hasArray
bool hasArray()

Returns {@code true} if and only if this buffer has a backing byte array. If this method returns true, you can safely call {@link #array()} and {@link #arrayOffset()}.

hasMemoryAddress
bool hasMemoryAddress()

Returns {@code true} if and only if this buffer has a reference to the low-level memory address that points to the backing data.

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

Locates the first occurrence of the specified {@code value} in this buffer. The search takes place from the specified {@code fromIndex} (inclusive) to the specified {@code toIndex} (exclusive). <p> If {@code fromIndex} is greater than {@code toIndex}, the search is performed in a reversed order. <p> This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

internalNioBuffer
ByteBuffer internalNioBuffer(int index, int length)

Internal use only: Exposes the internal NIO buffer.

isAccessible
bool isAccessible()

Used internally by {@link AbstractByteBuf#ensureAccessible()} to try to guard against using the buffer after it was released (best-effort).

isDirect
bool isDirect()

Returns {@code true} if and only if this buffer is backed by an NIO direct buffer.

isReadOnly
bool isReadOnly()

Returns {@code true} if and only if this buffer is read-only.

isReadable
bool isReadable(int size)

Returns {@code true} if and only if this buffer contains equal to or more than the specified number of elements.

isReadable
bool isReadable()

Returns {@code true} if and only if {@code (this.writerIndex - this.readerIndex)} is greater than {@code 0}.

isWritable
bool isWritable(int size)

Returns {@code true} if and only if this buffer has enough room to allow writing the specified number of elements.

isWritable
bool isWritable()

Returns {@code true} if and only if {@code (this.capacity - this.writerIndex)} is greater than {@code 0}.

markReaderIndex
ByteBuf markReaderIndex()

Marks the current {@code readerIndex} in this buffer. You can reposition the current {@code readerIndex} to the marked {@code readerIndex} by calling {@link #resetReaderIndex()}. The initial value of the marked {@code readerIndex} is {@code 0}.

markWriterIndex
ByteBuf markWriterIndex()

Marks the current {@code writerIndex} in this buffer. You can reposition the current {@code writerIndex} to the marked {@code writerIndex} by calling {@link #resetWriterIndex()}. The initial value of the marked {@code writerIndex} is {@code 0}.

maxCapacity
int maxCapacity()

Returns the maximum allowed capacity of this buffer. This value provides an upper bound on {@link #capacity()}.

maxFastWritableBytes
int maxFastWritableBytes()

Returns the maximum number of bytes which can be written for certain without involving an internal reallocation or data-copy. The returned value will be &ge; {@link #writableBytes()} and &le; {@link #maxWritableBytes()}.

maxWritableBytes
int maxWritableBytes()

Returns the maximum possible number of writable bytes, which is equal to {@code (this.maxCapacity - this.writerIndex)}.

memoryAddress
long memoryAddress()

Returns the low-level memory address that point to the first byte of ths backing data.

nioBuffer
ByteBuffer nioBuffer()

Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}. The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method is identical to {@code buf.nioBuffer(buf.readerIndex(), buf.readableBytes())}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.

nioBuffer
ByteBuffer nioBuffer(int index, int length)

Exposes this buffer's sub-region as an NIO {@link ByteBuffer}. The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.

nioBufferCount
int nioBufferCount()

Returns the maximum number of NIO {@link ByteBuffer}s that consist this buffer. Note that {@link #nioBuffers()} or {@link #nioBuffers(int, int)} might return a less number of {@link ByteBuffer}s.

nioBuffers
ByteBuffer[] nioBuffers()

Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}'s. The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.

nioBuffers
ByteBuffer[] nioBuffers(int index, int length)

Exposes this buffer's bytes as an NIO {@link ByteBuffer}'s for the specified index and length The returned buffer either share or contains the copied content of this buffer, while changing the position and limit of the returned NIO buffer does not affect the indexes and marks of this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity.

opEquals
bool opEquals(Object obj)

Determines if the content of the specified buffer is identical to the content of this array. 'Identical' here means: <ul> <li>the size of the contents of the two buffers are same and</li> <li>every single byte of the content of the two buffers are same.</li> </ul> Please note that it does not compare {@link #readerIndex()} nor {@link #writerIndex()}. This method also returns {@code false} for {@code null} and an object which is not an instance of {@link ByteBuf} type.

order
ByteOrder order()

Returns the <a href="http://en.wikipedia.org/wiki/Endianness">endianness</a> of this buffer.

readBoolean
bool readBoolean()

Gets a bool at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 1} in this buffer.

readByte
byte readByte()

Gets a byte at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 1} in this buffer.

readBytes
ByteBuf readBytes(int length)

Transfers this buffer's data to a newly created buffer starting at the current {@code readerIndex} and increases the {@code readerIndex} by the number of the transferred bytes (= {@code length}). The returned buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and {@code length} respectively.

readBytes
ByteBuf readBytes(ByteBuf dst)

Transfers this buffer's data to the specified destination starting at the current {@code readerIndex} until the destination becomes non-writable, and increases the {@code readerIndex} by the number of the transferred bytes. This method is basically same with {@link #readBytes(ByteBuf, int, int)}, except that this method increases the {@code writerIndex} of the destination by the number of the transferred bytes while {@link #readBytes(ByteBuf, int, int)} does not.

readBytes
ByteBuf readBytes(ByteBuf dst, int length)

Transfers this buffer's data to the specified destination starting at the current {@code readerIndex} and increases the {@code readerIndex} by the number of the transferred bytes (= {@code length}). This method is basically same with {@link #readBytes(ByteBuf, int, int)}, except that this method increases the {@code writerIndex} of the destination by the number of the transferred bytes (= {@code length}) while {@link #readBytes(ByteBuf, int, int)} does not.

readBytes
ByteBuf readBytes(ByteBuf dst, int dstIndex, int length)

Transfers this buffer's data to the specified destination starting at the current {@code readerIndex} and increases the {@code readerIndex} by the number of the transferred bytes (= {@code length}).

readBytes
ByteBuf readBytes(byte[] dst)

Transfers this buffer's data to the specified destination starting at the current {@code readerIndex} and increases the {@code readerIndex} by the number of the transferred bytes (= {@code dst.length}).

readBytes
ByteBuf readBytes(byte[] dst, int dstIndex, int length)

Transfers this buffer's data to the specified destination starting at the current {@code readerIndex} and increases the {@code readerIndex} by the number of the transferred bytes (= {@code length}).

readBytes
ByteBuf readBytes(ByteBuffer dst)

Transfers this buffer's data to the specified destination starting at the current {@code readerIndex} until the destination's position reaches its limit, and increases the {@code readerIndex} by the number of the transferred bytes.

readBytes
ByteBuf readBytes(OutputStream outStream, int length)

Transfers this buffer's data to the specified stream starting at the current {@code readerIndex}.

readChar
char readChar()

Gets a 2-byte UTF-16 character at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 2} in this buffer.

readCharSequence
CharSequence readCharSequence(int length, Charset charset)

Gets a {@link CharSequence} with the given length at the current {@code readerIndex} and increases the {@code readerIndex} by the given length.

readDouble
double readDouble()

Gets a 64-bit floating point number at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 8} in this buffer.

readDoubleLE
double readDoubleLE()

Gets a 64-bit floating point number at the current {@code readerIndex} in Little Endian Byte Order and increases the {@code readerIndex} by {@code 8} in this buffer.

readFloat
float readFloat()

Gets a 32-bit floating point number at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 4} in this buffer.

readFloatLE
float readFloatLE()

Gets a 32-bit floating point number at the current {@code readerIndex} in Little Endian Byte Order and increases the {@code readerIndex} by {@code 4} in this buffer.

readInt
int readInt()

Gets a 32-bit integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 4} in this buffer.

readIntLE
int readIntLE()

Gets a 32-bit integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 4} in this buffer.

readLong
long readLong()

Gets a 64-bit integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 8} in this buffer.

readLongLE
long readLongLE()

Gets a 64-bit integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 8} in this buffer.

readMedium
int readMedium()

Gets a 24-bit medium integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 3} in this buffer.

readMediumLE
int readMediumLE()

Gets a 24-bit medium integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 3} in this buffer.

readRetainedSlice
ByteBuf readRetainedSlice(int length)

Returns a new retained slice of this buffer's sub-region starting at the current {@code readerIndex} and increases the {@code readerIndex} by the size of the new slice (= {@code length}). <p> Note that this method returns a {@linkplain #retain() retained} buffer unlike {@link #readSlice(int)}. This method behaves similarly to {@code readSlice(...).retain()} except that this method may return a buffer implementation that produces less garbage.

readShort
short readShort()

Gets a 16-bit short integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 2} in this buffer.

readShortLE
short readShortLE()

Gets a 16-bit short integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 2} in this buffer.

readSlice
ByteBuf readSlice(int length)

Returns a new slice of this buffer's sub-region starting at the current {@code readerIndex} and increases the {@code readerIndex} by the size of the new slice (= {@code length}). <p> Also be aware that this method will NOT call {@link #retain()} and so the reference count will NOT be increased.

readUnsignedByte
short readUnsignedByte()

Gets an unsigned byte at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 1} in this buffer.

readUnsignedInt
long readUnsignedInt()

Gets an unsigned 32-bit integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 4} in this buffer.

readUnsignedIntLE
long readUnsignedIntLE()

Gets an unsigned 32-bit integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 4} in this buffer.

readUnsignedMedium
int readUnsignedMedium()

Gets an unsigned 24-bit medium integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 3} in this buffer.

readUnsignedMediumLE
int readUnsignedMediumLE()

Gets an unsigned 24-bit medium integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 3} in this buffer.

readUnsignedShort
int readUnsignedShort()

Gets an unsigned 16-bit short integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 2} in this buffer.

readUnsignedShortLE
int readUnsignedShortLE()

Gets an unsigned 16-bit short integer at the current {@code readerIndex} in the Little Endian Byte Order and increases the {@code readerIndex} by {@code 2} in this buffer.

readableBytes
int readableBytes()

Returns the number of readable bytes which is equal to {@code (this.writerIndex - this.readerIndex)}.

readerIndex
ByteBuf readerIndex(int readerIndex)

Sets the {@code readerIndex} of this buffer.

readerIndex
int readerIndex()

Returns the {@code readerIndex} of this buffer.

resetReaderIndex
ByteBuf resetReaderIndex()

Repositions the current {@code readerIndex} to the marked {@code readerIndex} in this buffer.

resetWriterIndex
ByteBuf resetWriterIndex()

Repositions the current {@code writerIndex} to the marked {@code writerIndex} in this buffer.

retain
ByteBuf retain(int increment)
Undocumented in source.
retain
ByteBuf retain()
Undocumented in source.
retainedDuplicate
ByteBuf retainedDuplicate()

Returns a retained buffer which shares the whole region of this buffer. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to {@code buf.slice(0, buf.capacity())}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. <p> Note that this method returns a {@linkplain #retain() retained} buffer unlike {@link #slice(int, int)}. This method behaves similarly to {@code duplicate().retain()} except that this method may return a buffer implementation that produces less garbage.

retainedSlice
ByteBuf retainedSlice()

Returns a retained slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to {@code buf.slice(buf.readerIndex(), buf.readableBytes())}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. <p> Note that this method returns a {@linkplain #retain() retained} buffer unlike {@link #slice()}. This method behaves similarly to {@code slice().retain()} except that this method may return a buffer implementation that produces less garbage.

retainedSlice
ByteBuf retainedSlice(int index, int length)

Returns a retained slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. <p> Note that this method returns a {@linkplain #retain() retained} buffer unlike {@link #slice(int, int)}. This method behaves similarly to {@code slice(...).retain()} except that this method may return a buffer implementation that produces less garbage.

setBoolean
ByteBuf setBoolean(int index, bool value)

Sets the specified bool at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setByte
ByteBuf setByte(int index, int value)

Sets the specified byte at the specified absolute {@code index} in this buffer. The 24 high-order bits of the specified value are ignored. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setBytes
ByteBuf setBytes(int index, ByteBuf src)

Transfers the specified source buffer's data to this buffer starting at the specified absolute {@code index} until the source buffer becomes unreadable. This method is basically same with {@link #setBytes(int, ByteBuf, int, int)}, except that this method increases the {@code readerIndex} of the source buffer by the number of the transferred bytes while {@link #setBytes(int, ByteBuf, int, int)} does not. This method does not modify {@code readerIndex} or {@code writerIndex} of the source buffer (i.e. {@code this}).

setBytes
ByteBuf setBytes(int index, ByteBuf src, int length)

Transfers the specified source buffer's data to this buffer starting at the specified absolute {@code index}. This method is basically same with {@link #setBytes(int, ByteBuf, int, int)}, except that this method increases the {@code readerIndex} of the source buffer by the number of the transferred bytes while {@link #setBytes(int, ByteBuf, int, int)} does not. This method does not modify {@code readerIndex} or {@code writerIndex} of the source buffer (i.e. {@code this}).

setBytes
ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length)

Transfers the specified source buffer's data to this buffer starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of both the source (i.e. {@code this}) and the destination.

setBytes
ByteBuf setBytes(int index, byte[] src)

Transfers the specified source array's data to this buffer starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setBytes
ByteBuf setBytes(int index, byte[] src, int srcIndex, int length)

Transfers the specified source array's data to this buffer starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setBytes
ByteBuf setBytes(int index, ByteBuffer src)

Transfers the specified source buffer's data to this buffer starting at the specified absolute {@code index} until the source buffer's position reaches its limit. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setBytes
int setBytes(int index, InputStream inStream, int length)

Transfers the content of the specified source stream to this buffer starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setChar
ByteBuf setChar(int index, int value)

Sets the specified 2-byte UTF-16 character at the specified absolute {@code index} in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setCharSequence
int setCharSequence(int index, CharSequence sequence, Charset charset)

Writes the specified {@link CharSequence} at the current {@code writerIndex} and increases the {@code writerIndex} by the written bytes.

setDouble
ByteBuf setDouble(int index, double value)

Sets the specified 64-bit floating-point number at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setDoubleLE
ByteBuf setDoubleLE(int index, double value)

Sets the specified 64-bit floating-point number at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setFloat
ByteBuf setFloat(int index, float value)

Sets the specified 32-bit floating-point number at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setFloatLE
ByteBuf setFloatLE(int index, float value)

Sets the specified 32-bit floating-point number at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setIndex
ByteBuf setIndex(int readerIndex, int writerIndex)

Sets the {@code readerIndex} and {@code writerIndex} of this buffer in one shot. This method is useful when you have to worry about the invocation order of {@link #readerIndex(int)} and {@link #writerIndex(int)} methods. For example, the following code will fail:

setInt
ByteBuf setInt(int index, int value)

Sets the specified 32-bit integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setIntLE
ByteBuf setIntLE(int index, int value)

Sets the specified 32-bit integer at the specified absolute {@code index} in this buffer with Little Endian byte order . This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setLong
ByteBuf setLong(int index, long value)

Sets the specified 64-bit long integer at the specified absolute {@code index} in this buffer. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setLongLE
ByteBuf setLongLE(int index, long value)

Sets the specified 64-bit long integer at the specified absolute {@code index} in this buffer in Little Endian Byte Order. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setMedium
ByteBuf setMedium(int index, int value)

Sets the specified 24-bit medium integer at the specified absolute {@code index} in this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setMediumLE
ByteBuf setMediumLE(int index, int value)

Sets the specified 24-bit medium integer at the specified absolute {@code index} in this buffer in the Little Endian Byte Order. Please note that the most significant byte is ignored in the specified value. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setShort
ByteBuf setShort(int index, int value)

Sets the specified 16-bit short integer at the specified absolute {@code index} in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setShortLE
ByteBuf setShortLE(int index, int value)

Sets the specified 16-bit short integer at the specified absolute {@code index} in this buffer with the Little Endian Byte Order. The 16 high-order bits of the specified value are ignored. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

setZero
ByteBuf setZero(int index, int length)

Fills this buffer with <tt>NUL (0x00)</tt> starting at the specified absolute {@code index}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

skipBytes
ByteBuf skipBytes(int length)

Increases the current {@code readerIndex} by the specified {@code length} in this buffer.

slice
ByteBuf slice()

Returns a slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to {@code buf.slice(buf.readerIndex(), buf.readableBytes())}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. <p> Also be aware that this method will NOT call {@link #retain()} and so the reference count will NOT be increased.

slice
ByteBuf slice(int index, int length)

Returns a slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer. <p> Also be aware that this method will NOT call {@link #retain()} and so the reference count will NOT be increased.

toHash
size_t toHash()

Returns a hash code which was calculated from the content of this buffer. If there's a byte array which is {@linkplain #equals(Object) equal to} this array, both arrays should return the same value.

toString
string toString(Charset charset)

Decodes this buffer's readable bytes into a string with the specified character set name. This method is identical to {@code buf.toString(buf.readerIndex(), buf.readableBytes(), charsetName)}. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

toString
string toString(int index, int length, Charset charset)

Decodes this buffer's sub-region into a string with the specified character set. This method does not modify {@code readerIndex} or {@code writerIndex} of this buffer.

toString
string toString()

Returns the string representation of this buffer. This method does not necessarily return the whole content of the buffer but returns the values of the key properties such as {@link #readerIndex()}, {@link #writerIndex()} and {@link #capacity()}.

touch
ByteBuf touch()
Undocumented in source.
touch
ByteBuf touch(Object hint)
Undocumented in source.
unwrap
ByteBuf unwrap()

Return the underlying buffer instance if this buffer is a wrapper of another buffer.

writableBytes
int writableBytes()

Returns the number of writable bytes which is equal to {@code (this.capacity - this.writerIndex)}.

writeBoolean
ByteBuf writeBoolean(bool value)

Sets the specified bool at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 1} in this buffer. If {@code this.writableBytes} is less than {@code 1}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeByte
ByteBuf writeByte(int value)

Sets the specified byte at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 1} in this buffer. The 24 high-order bits of the specified value are ignored. If {@code this.writableBytes} is less than {@code 1}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
ByteBuf writeBytes(ByteBuf src)

Transfers the specified source buffer's data to this buffer starting at the current {@code writerIndex} until the source buffer becomes unreadable, and increases the {@code writerIndex} by the number of the transferred bytes. This method is basically same with {@link #writeBytes(ByteBuf, int, int)}, except that this method increases the {@code readerIndex} of the source buffer by the number of the transferred bytes while {@link #writeBytes(ByteBuf, int, int)} does not. If {@code this.writableBytes} is less than {@code src.readableBytes}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
ByteBuf writeBytes(ByteBuf src, int length)

Transfers the specified source buffer's data to this buffer starting at the current {@code writerIndex} and increases the {@code writerIndex} by the number of the transferred bytes (= {@code length}). This method is basically same with {@link #writeBytes(ByteBuf, int, int)}, except that this method increases the {@code readerIndex} of the source buffer by the number of the transferred bytes (= {@code length}) while {@link #writeBytes(ByteBuf, int, int)} does not. If {@code this.writableBytes} is less than {@code length}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
ByteBuf writeBytes(ByteBuf src, int srcIndex, int length)

Transfers the specified source buffer's data to this buffer starting at the current {@code writerIndex} and increases the {@code writerIndex} by the number of the transferred bytes (= {@code length}). If {@code this.writableBytes} is less than {@code length}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
ByteBuf writeBytes(byte[] src)

Transfers the specified source array's data to this buffer starting at the current {@code writerIndex} and increases the {@code writerIndex} by the number of the transferred bytes (= {@code src.length}). If {@code this.writableBytes} is less than {@code src.length}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
ByteBuf writeBytes(byte[] src, int srcIndex, int length)

Transfers the specified source array's data to this buffer starting at the current {@code writerIndex} and increases the {@code writerIndex} by the number of the transferred bytes (= {@code length}). If {@code this.writableBytes} is less than {@code length}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
ByteBuf writeBytes(ByteBuffer src)

Transfers the specified source buffer's data to this buffer starting at the current {@code writerIndex} until the source buffer's position reaches its limit, and increases the {@code writerIndex} by the number of the transferred bytes. If {@code this.writableBytes} is less than {@code src.remaining()}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeBytes
int writeBytes(InputStream inStream, int length)

Transfers the content of the specified stream to this buffer starting at the current {@code writerIndex} and increases the {@code writerIndex} by the number of the transferred bytes. If {@code this.writableBytes} is less than {@code length}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeChar
ByteBuf writeChar(int value)

Sets the specified 2-byte UTF-16 character at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 2} in this buffer. The 16 high-order bits of the specified value are ignored. If {@code this.writableBytes} is less than {@code 2}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeCharSequence
int writeCharSequence(CharSequence sequence, Charset charset)

Writes the specified {@link CharSequence} at the current {@code writerIndex} and increases the {@code writerIndex} by the written bytes. in this buffer. If {@code this.writableBytes} is not large enough to write the whole sequence, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeDouble
ByteBuf writeDouble(double value)

Sets the specified 64-bit floating point number at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 8} in this buffer. If {@code this.writableBytes} is less than {@code 8}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeDoubleLE
ByteBuf writeDoubleLE(double value)

Sets the specified 64-bit floating point number at the current {@code writerIndex} in Little Endian Byte Order and increases the {@code writerIndex} by {@code 8} in this buffer. If {@code this.writableBytes} is less than {@code 8}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeFloat
ByteBuf writeFloat(float value)

Sets the specified 32-bit floating point number at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 4} in this buffer. If {@code this.writableBytes} is less than {@code 4}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeFloatLE
ByteBuf writeFloatLE(float value)

Sets the specified 32-bit floating point number at the current {@code writerIndex} in Little Endian Byte Order and increases the {@code writerIndex} by {@code 4} in this buffer. If {@code this.writableBytes} is less than {@code 4}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeInt
ByteBuf writeInt(int value)

Sets the specified 32-bit integer at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 4} in this buffer. If {@code this.writableBytes} is less than {@code 4}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeIntLE
ByteBuf writeIntLE(int value)

Sets the specified 32-bit integer at the current {@code writerIndex} in the Little Endian Byte Order and increases the {@code writerIndex} by {@code 4} in this buffer. If {@code this.writableBytes} is less than {@code 4}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeLong
ByteBuf writeLong(long value)

Sets the specified 64-bit long integer at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 8} in this buffer. If {@code this.writableBytes} is less than {@code 8}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeLongLE
ByteBuf writeLongLE(long value)

Sets the specified 64-bit long integer at the current {@code writerIndex} in the Little Endian Byte Order and increases the {@code writerIndex} by {@code 8} in this buffer. If {@code this.writableBytes} is less than {@code 8}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeMedium
ByteBuf writeMedium(int value)

Sets the specified 24-bit medium integer at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 3} in this buffer. If {@code this.writableBytes} is less than {@code 3}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeMediumLE
ByteBuf writeMediumLE(int value)

Sets the specified 24-bit medium integer at the current {@code writerIndex} in the Little Endian Byte Order and increases the {@code writerIndex} by {@code 3} in this buffer. If {@code this.writableBytes} is less than {@code 3}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeShort
ByteBuf writeShort(int value)

Sets the specified 16-bit short integer at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 2} in this buffer. The 16 high-order bits of the specified value are ignored. If {@code this.writableBytes} is less than {@code 2}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeShortLE
ByteBuf writeShortLE(int value)

Sets the specified 16-bit short integer in the Little Endian Byte Order at the current {@code writerIndex} and increases the {@code writerIndex} by {@code 2} in this buffer. The 16 high-order bits of the specified value are ignored. If {@code this.writableBytes} is less than {@code 2}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writeZero
ByteBuf writeZero(int length)

Fills this buffer with <tt>NUL (0x00)</tt> starting at the current {@code writerIndex} and increases the {@code writerIndex} by the specified {@code length}. If {@code this.writableBytes} is less than {@code length}, {@link #ensureWritable(int)} will be called in an attempt to expand capacity to accommodate.

writerIndex
ByteBuf writerIndex(int writerIndex)

Sets the {@code writerIndex} of this buffer.

writerIndex
int writerIndex()

Returns the {@code writerIndex} of this buffer.

Inherited Members

From ReferenceCounted

refCnt
int refCnt()

Returns the reference count of this object. If {@code 0}, it means this object has been deallocated.

retain
ReferenceCounted retain()

Increases the reference count by {@code 1}.

retain
ReferenceCounted retain(int increment)

Increases the reference count by the specified {@code increment}.

touch
ReferenceCounted touch()

Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via {@link ResourceLeakDetector}. This method is a shortcut to {@link #touch(Object) touch(null)}.

touch
ReferenceCounted touch(Object hint)

Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via {@link ResourceLeakDetector}.

release
bool release()

Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at {@code 0}.

release
bool release(int decrement)

Decreases the reference count by the specified {@code decrement} and deallocates this object if the reference count reaches at {@code 0}.

Detailed Description

AFTER discardReadBytes()

+------------------+--------------------------------------+ | readable bytes | writable bytes (got more space) | +------------------+--------------------------------------+ | | | readerIndex (0) <= writerIndex (decreased) <= capacity </pre>

Please note that there is no guarantee about the content of writable bytes after calling {@link #discardReadBytes()}. The writable bytes will not be moved in most cases and could even be filled with completely different data depending on the underlying buffer implementation.

<h4>Clearing the buffer indexes</h4>

You can set both {@link #readerIndex() readerIndex} and {@link #writerIndex() writerIndex} to {@code 0} by calling {@link #clear()}. It does not clear the buffer content (e.g. filling with {@code 0}) but just clears the two pointers. Please also note that the semantic of this operation is different from {@link ByteBuffer#clear()}.

<pre> BEFORE clear()

+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity

AFTER clear()

+---------------------------------------------------------+ | writable bytes (got more space) | +---------------------------------------------------------+ | | 0 = readerIndex = writerIndex <= capacity </pre>

<h3>Search operations</h3>

For simple single-byte searches, use {@link #indexOf(int, int, byte)} and {@link #bytesBefore(int, int, byte)}. {@link #bytesBefore(byte)} is especially useful when you deal with a {@code NUL}-terminated string. For complicated searches, use {@link #forEachByte(int, int, ByteProcessor)} with a {@link ByteProcessor} implementation.

<h3>Mark and reset</h3>

There are two marker indexes in every buffer. One is for storing {@link #readerIndex() readerIndex} and the other is for storing {@link #writerIndex() writerIndex}. You can always reposition one of the two indexes by calling a reset method. It works in a similar fashion to the mark and reset methods in {@link InputStream} except that there's no {@code readlimit}.

<h3>Derived buffers</h3>

You can create a view of an existing buffer by calling one of the following methods: <ul> <li>{@link #duplicate()}</li> <li>{@link #slice()}</li> <li>{@link #slice(int, int)}</li> <li>{@link #readSlice(int)}</li> <li>{@link #retainedDuplicate()}</li> <li>{@link #retainedSlice()}</li> <li>{@link #retainedSlice(int, int)}</li> <li>{@link #readRetainedSlice(int)}</li> </ul> A derived buffer will have an independent {@link #readerIndex() readerIndex}, {@link #writerIndex() writerIndex} and marker indexes, while it shares other internal data representation, just like a NIO buffer does. <p> In case a completely fresh copy of an existing buffer is required, please call {@link #copy()} method instead.

<h4>Non-retained and retained derived buffers</h4>

Note that the {@link #duplicate()}, {@link #slice()}, {@link #slice(int, int)} and {@link #readSlice(int)} does NOT call {@link #retain()} on the returned derived buffer, and thus its reference count will NOT be increased. If you need to create a derived buffer with increased reference count, consider using {@link #retainedDuplicate()}, {@link #retainedSlice()}, {@link #retainedSlice(int, int)} and {@link #readRetainedSlice(int)} which may return a buffer implementation that produces less garbage.

<h3>Conversion to existing JDK types</h3>

<h4>Byte array</h4>

If a {@link ByteBuf} is backed by a byte array (i.e. {@code byte[]}), you can access it directly via the {@link #array()} method. To determine if a buffer is backed by a byte array, {@link #hasArray()} should be used.

<h4>NIO Buffers</h4>

If a {@link ByteBuf} can be converted into an NIO {@link ByteBuffer} which shares its content (i.e. view buffer), you can get it via the {@link #nioBuffer()} method. To determine if a buffer can be converted into an NIO buffer, use {@link #nioBufferCount()}.

<h4>Strings</h4>

Various {@link #toString(Charset)} methods convert a {@link ByteBuf} into a {@link string}. Please note that {@link #toString()} is not a conversion method.

<h4>I/O Streams</h4>

Please refer to {@link ByteBufInputStream} and {@link ByteBufOutputStream}.

Meta