Returns the {@link ByteBufAllocator} which created this buffer.
Returns the backing byte array of this buffer.
Returns the offset of the first byte within the backing byte array of this buffer.
Returns a read-only version of this buffer.
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.
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.
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.
Returns the number of bytes (octets) this buffer can contain.
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)}.
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.
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)}.
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.
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.
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.
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.
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.
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.
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.
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)})
Iterates over the readable bytes of this buffer with the specified {@code processor} in ascending order.
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})
Iterates over the readable bytes of this buffer with the specified {@code processor} in descending order.
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.
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.
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.
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.
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.
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}).
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.
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}).
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
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.
Gets a {@link CharSequence} with the given length at the given 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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()}.
Returns {@code true} if and only if this buffer has a reference to the low-level memory address that points to the backing data.
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.
Internal use only: Exposes the internal NIO buffer.
Used internally by {@link AbstractByteBuf#ensureAccessible()} to try to guard against using the buffer after it was released (best-effort).
Returns {@code true} if and only if this buffer is backed by an NIO direct buffer.
Returns {@code true} if and only if this buffer is read-only.
Returns {@code true} if and only if this buffer contains equal to or more than the specified number of elements.
Returns {@code true} if and only if {@code (this.writerIndex - this.readerIndex)} is greater than {@code 0}.
Returns {@code true} if and only if this buffer has enough room to allow writing the specified number of elements.
Returns {@code true} if and only if {@code (this.capacity - this.writerIndex)} is greater than {@code 0}.
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}.
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}.
Returns the maximum allowed capacity of this buffer. This value provides an upper bound on {@link #capacity()}.
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 ≥ {@link #writableBytes()} and ≤ {@link #maxWritableBytes()}.
Returns the maximum possible number of writable bytes, which is equal to {@code (this.maxCapacity - this.writerIndex)}.
Returns the low-level memory address that point to the first byte of ths backing data.
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.
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.
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.
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.
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.
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.
Returns the <a href="http://en.wikipedia.org/wiki/Endianness">endianness</a> of this buffer.
Gets a bool at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 1} in this buffer.
Gets a byte at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 1} in this buffer.
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.
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.
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.
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}).
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}).
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}).
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.
Transfers this buffer's data to the specified stream starting at the current {@code readerIndex}.
Gets a 2-byte UTF-16 character at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 2} in this buffer.
Gets a {@link CharSequence} with the given length at the current {@code readerIndex} and increases the {@code readerIndex} by the given length.
Gets a 64-bit floating point number at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 8} in this buffer.
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.
Gets a 32-bit floating point number at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 4} in this buffer.
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.
Gets a 32-bit integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 4} in this buffer.
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.
Gets a 64-bit integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 8} in this buffer.
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.
Gets a 24-bit medium integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 3} in this buffer.
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.
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.
Gets a 16-bit short integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 2} in this buffer.
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.
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.
Gets an unsigned byte at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 1} in this buffer.
Gets an unsigned 32-bit integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 4} in this buffer.
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.
Gets an unsigned 24-bit medium integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 3} in this buffer.
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.
Gets an unsigned 16-bit short integer at the current {@code readerIndex} and increases the {@code readerIndex} by {@code 2} in this buffer.
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.
Returns the number of readable bytes which is equal to {@code (this.writerIndex - this.readerIndex)}.
Sets the {@code readerIndex} of this buffer.
Returns the {@code readerIndex} of this buffer.
Repositions the current {@code readerIndex} to the marked {@code readerIndex} in this buffer.
Repositions the current {@code writerIndex} to the marked {@code writerIndex} in this buffer.
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.
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.
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.
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.
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.
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}).
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}).
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.
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.
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.
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.
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.
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.
Writes the specified {@link CharSequence} at the current {@code writerIndex} and increases the {@code writerIndex} by the written bytes.
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.
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.
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.
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.
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:
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.
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.
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.
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.
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.
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.
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.
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.
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.
Increases the current {@code readerIndex} by the specified {@code length} in this buffer.
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.
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.
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.
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.
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.
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()}.
Return the underlying buffer instance if this buffer is a wrapper of another buffer.
Returns the number of writable bytes which is equal to {@code (this.capacity - this.writerIndex)}.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Sets the {@code writerIndex} of this buffer.
Returns the {@code writerIndex} of this buffer.
Returns the reference count of this object. If {@code 0}, it means this object has been deallocated.
Increases the reference count by {@code 1}.
Increases the reference count by the specified {@code increment}.
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)}.
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}.
Decreases the reference count by {@code 1} and deallocates this object if the reference count reaches at {@code 0}.
Decreases the reference count by the specified {@code decrement} and deallocates this object if the reference count reaches at {@code 0}.
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}.
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 < 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