ByteBuf by allocating new space or by wrapping
or copying existing byte arrays, byte buffers and a string.
import static io.netty.buffer.Unpooled.*;ByteBufheapBuffer = buffer(128);ByteBufdirectBuffer = directBuffer(256);ByteBufwrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);ByteBufcopiedBuffer = copiedBuffer(ByteBuffer.allocate(128));
buffer(int) allocates a new fixed-capacity heap buffer.directBuffer(int) allocates a new fixed-capacity direct buffer.wrappedBuffer().
You might want to take a look at the methods that accept varargs closely if
you want to create a buffer which is composed of more than one array to
reduce the number of memory copy.
copiedBuffer(). It is also convenient
to use this operation to merge multiple buffers into one buffer.
| Modifier and Type | Field and Description |
|---|---|
| private static final ByteBufAllocator | |
| public static final ByteOrder | BIG_ENDIAN
Big endian byte order. |
| public static final ByteBuf | EMPTY_BUFFER
A buffer whose capacity is |
| public static final ByteOrder | LITTLE_ENDIAN
Little endian byte order. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ByteBuf | buffer()
Creates a new big-endian Java heap buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand. |
| public static ByteBuf | buffer(int initialCapacity)
Creates a new big-endian Java heap buffer with the specified |
| public static ByteBuf | buffer(int initialCapacity, int maxCapacity)
Creates a new big-endian Java heap buffer with the specified
|
| public static CompositeByteBuf | |
| public static CompositeByteBuf | |
| public static ByteBuf | copiedBuffer(byte[] array)
Creates a new big-endian buffer whose content is a copy of the
specified |
| public static ByteBuf | copiedBuffer(byte[] array, int offset, int length)
Creates a new big-endian buffer whose content is a copy of the
specified |
| public static ByteBuf | copiedBuffer(ByteBuffer buffer)
Creates a new buffer whose content is a copy of the specified
|
| public static ByteBuf | copiedBuffer(ByteBuf buffer)
Creates a new buffer whose content is a copy of the specified
|
| public static ByteBuf | copiedBuffer(byte[]... arrays)
Creates a new big-endian buffer whose content is a merged copy of
the specified |
| public static ByteBuf | copiedBuffer(ByteBuf... buffers)
Creates a new buffer whose content is a merged copy of the specified
|
| public static ByteBuf | copiedBuffer(ByteBuffer... buffers)
Creates a new buffer whose content is a merged copy of the specified
|
| public static ByteBuf | copiedBuffer(CharSequence string, Charset charset)
Creates a new big-endian buffer whose content is the specified
|
| public static ByteBuf | copiedBuffer(CharSequence string, int offset, int length, Charset charset)
Creates a new big-endian buffer whose content is a subregion of
the specified |
| public static ByteBuf | copiedBuffer(char[] array, Charset charset)
Creates a new big-endian buffer whose content is the specified
|
| public static ByteBuf | copiedBuffer(char[] array, int offset, int length, Charset charset)
Creates a new big-endian buffer whose content is a subregion of
the specified |
| private static ByteBuf | |
| private static ByteBuf | |
| private static ByteBuf | |
| public static ByteBuf | copyBoolean(boolean value)
Creates a new single-byte big-endian buffer that holds the specified boolean value. |
| public static ByteBuf | copyBoolean(boolean... values)
Create a new big-endian buffer that holds a sequence of the specified boolean values. |
| public static ByteBuf | copyDouble(double value)
Creates a new 8-byte big-endian buffer that holds the specified 64-bit floating point number. |
| public static ByteBuf | copyDouble(double... values)
Create a new big-endian buffer that holds a sequence of the specified 64-bit floating point numbers. |
| public static ByteBuf | copyFloat(float value)
Creates a new 4-byte big-endian buffer that holds the specified 32-bit floating point number. |
| public static ByteBuf | copyFloat(float... values)
Create a new big-endian buffer that holds a sequence of the specified 32-bit floating point numbers. |
| public static ByteBuf | |
| public static ByteBuf | copyInt(int... values)
Create a big-endian buffer that holds a sequence of the specified 32-bit integers. |
| public static ByteBuf | |
| public static ByteBuf | copyLong(long... values)
Create a new big-endian buffer that holds a sequence of the specified 64-bit integers. |
| public static ByteBuf | copyMedium(int value)
Creates a new 3-byte big-endian buffer that holds the specified 24-bit integer. |
| public static ByteBuf | copyMedium(int... values)
Create a new big-endian buffer that holds a sequence of the specified 24-bit integers. |
| public static ByteBuf | |
| public static ByteBuf | copyShort(short... values)
Create a new big-endian buffer that holds a sequence of the specified 16-bit integers. |
| public static ByteBuf | copyShort(int... values)
Create a new big-endian buffer that holds a sequence of the specified 16-bit integers. |
| public static ByteBuf | directBuffer()
Creates a new big-endian direct buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand. |
| public static ByteBuf | directBuffer(int initialCapacity)
Creates a new big-endian direct buffer with the specified |
| public static ByteBuf | directBuffer(int initialCapacity, int maxCapacity)
Creates a new big-endian direct buffer with the specified
|
| public static ByteBuf | unmodifiableBuffer(ByteBuf buffer)
Deprecated
Use
Creates a read-only buffer which disallows any modification operations
on the specified ByteBuf#asReadOnly().
buffer.
|
| public static ByteBuf | unmodifiableBuffer(ByteBuf... buffers)
Deprecated
Use
Wrap the given wrappedUnmodifiableBuffer(ByteBuf..
ByteBufs in an unmodifiable ByteBuf.
|
| public static ByteBuf | unreleasableBuffer(ByteBuf buf)
Return a unreleasable view on the given |
| public static ByteBuf | |
| public static ByteBuf | wrappedBuffer(byte[] array, int offset, int length)
Creates a new big-endian buffer which wraps the sub-region of the
specified |
| public static ByteBuf | wrappedBuffer(ByteBuffer buffer)
Creates a new buffer which wraps the specified NIO buffer's current slice. |
| public static ByteBuf | wrappedBuffer(long memoryAddress, int size, boolean doFree)
Creates a new buffer which wraps the specified memory address. |
| public static ByteBuf | Returns: The readable portion of thebuffer, or an empty buffer if there is no readable portion.
The caller is responsible for releasing this buffer.The buffer to wrap. Reference count ownership of this variable is transferred to this method. buffer)Creates a new buffer which wraps the specified buffer's readable bytes. |
| public static ByteBuf | wrappedBuffer(byte[]... arrays)
Creates a new big-endian composite buffer which wraps the specified arrays without copying them. |
| public static ByteBuf | Returns: The readable portion of thebuffers. The caller is responsible for releasing this buffer.The buffers to wrap. Reference count ownership of all variables is transferred to this method. buffers)Creates a new big-endian composite buffer which wraps the readable bytes of the specified buffers without copying them. |
| public static ByteBuf | wrappedBuffer(ByteBuffer... buffers)
Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them. |
| pack-priv static <T> ByteBuf | |
| public static ByteBuf | wrappedBuffer(int maxNumComponents, byte[]... arrays)
Creates a new big-endian composite buffer which wraps the specified arrays without copying them. |
| public static ByteBuf | Returns: The readable portion of thebuffers. The caller is responsible for releasing this buffer.Advisement as to how many independent buffers are allowed to exist before
consolidation occurs. maxNumComponents, ByteBuf... The buffers to wrap. Reference count ownership of all variables is transferred to this method. buffers)Creates a new big-endian composite buffer which wraps the readable bytes of the specified buffers without copying them. |
| public static ByteBuf | wrappedBuffer(int maxNumComponents, ByteBuffer... buffers)
Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them. |
| public static ByteBuf | |
| private static ByteBuf |
| ALLOC | back to summary |
|---|---|
| private static final ByteBufAllocator ALLOC | |
| BIG_ENDIAN | back to summary |
|---|---|
| public static final ByteOrder BIG_ENDIAN Big endian byte order. | |
| EMPTY_BUFFER | back to summary |
|---|---|
| public static final ByteBuf EMPTY_BUFFER A buffer whose capacity is
| |
| LITTLE_ENDIAN | back to summary |
|---|---|
| public static final ByteOrder LITTLE_ENDIAN Little endian byte order. | |
| Unpooled | back to summary |
|---|---|
| private Unpooled() | |
| buffer | back to summary |
|---|---|
| public static ByteBuf buffer() Creates a new big-endian Java heap buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand. | |
| buffer | back to summary |
|---|---|
| public static ByteBuf buffer(int initialCapacity) Creates a new big-endian Java heap buffer with the specified | |
| buffer | back to summary |
|---|---|
| public static ByteBuf buffer(int initialCapacity, int maxCapacity) Creates a new big-endian Java heap buffer with the specified
| |
| compositeBuffer | back to summary |
|---|---|
| public static CompositeByteBuf compositeBuffer() Returns a new big-endian composite buffer with no components. | |
| compositeBuffer | back to summary |
|---|---|
| public static CompositeByteBuf compositeBuffer(int maxNumComponents) Returns a new big-endian composite buffer with no components. | |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(byte[] array) Creates a new big-endian buffer whose content is a copy of the
specified | |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(byte[] array, int offset, int length) Creates a new big-endian buffer whose content is a copy of the
specified | |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(ByteBuffer buffer) Creates a new buffer whose content is a copy of the specified
| |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(ByteBuf buffer) Creates a new buffer whose content is a copy of the specified
| |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(byte[]... arrays) Creates a new big-endian buffer whose content is a merged copy of
the specified | |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(ByteBuf... buffers) Creates a new buffer whose content is a merged copy of the specified
| |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(ByteBuffer... buffers) Creates a new buffer whose content is a merged copy of the specified
| |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(CharSequence string, Charset charset) Creates a new big-endian buffer whose content is the specified
| |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(CharSequence string, int offset, int length, Charset charset) Creates a new big-endian buffer whose content is a subregion of
the specified | |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(char[] array, Charset charset) Creates a new big-endian buffer whose content is the specified
| |
| copiedBuffer | back to summary |
|---|---|
| public static ByteBuf copiedBuffer(char[] array, int offset, int length, Charset charset) Creates a new big-endian buffer whose content is a subregion of
the specified | |
| copiedBuffer | back to summary |
|---|---|
| private static ByteBuf copiedBuffer(CharBuffer buffer, Charset charset) | |
| copiedBufferAscii | back to summary |
|---|---|
| private static ByteBuf copiedBufferAscii(CharSequence string) | |
| copiedBufferUtf8 | back to summary |
|---|---|
| private static ByteBuf copiedBufferUtf8(CharSequence string) | |
| copyBoolean | back to summary |
|---|---|
| public static ByteBuf copyBoolean(boolean value) Creates a new single-byte big-endian buffer that holds the specified boolean value. | |
| copyBoolean | back to summary |
|---|---|
| public static ByteBuf copyBoolean(boolean... values) Create a new big-endian buffer that holds a sequence of the specified boolean values. | |
| copyDouble | back to summary |
|---|---|
| public static ByteBuf copyDouble(double value) Creates a new 8-byte big-endian buffer that holds the specified 64-bit floating point number. | |
| copyDouble | back to summary |
|---|---|
| public static ByteBuf copyDouble(double... values) Create a new big-endian buffer that holds a sequence of the specified 64-bit floating point numbers. | |
| copyFloat | back to summary |
|---|---|
| public static ByteBuf copyFloat(float value) Creates a new 4-byte big-endian buffer that holds the specified 32-bit floating point number. | |
| copyFloat | back to summary |
|---|---|
| public static ByteBuf copyFloat(float... values) Create a new big-endian buffer that holds a sequence of the specified 32-bit floating point numbers. | |
| copyInt | back to summary |
|---|---|
| public static ByteBuf copyInt(int value) Creates a new 4-byte big-endian buffer that holds the specified 32-bit integer. | |
| copyInt | back to summary |
|---|---|
| public static ByteBuf copyInt(int... values) Create a big-endian buffer that holds a sequence of the specified 32-bit integers. | |
| copyLong | back to summary |
|---|---|
| public static ByteBuf copyLong(long value) Creates a new 8-byte big-endian buffer that holds the specified 64-bit integer. | |
| copyLong | back to summary |
|---|---|
| public static ByteBuf copyLong(long... values) Create a new big-endian buffer that holds a sequence of the specified 64-bit integers. | |
| copyMedium | back to summary |
|---|---|
| public static ByteBuf copyMedium(int value) Creates a new 3-byte big-endian buffer that holds the specified 24-bit integer. | |
| copyMedium | back to summary |
|---|---|
| public static ByteBuf copyMedium(int... values) Create a new big-endian buffer that holds a sequence of the specified 24-bit integers. | |
| copyShort | back to summary |
|---|---|
| public static ByteBuf copyShort(int value) Creates a new 2-byte big-endian buffer that holds the specified 16-bit integer. | |
| copyShort | back to summary |
|---|---|
| public static ByteBuf copyShort(short... values) Create a new big-endian buffer that holds a sequence of the specified 16-bit integers. | |
| copyShort | back to summary |
|---|---|
| public static ByteBuf copyShort(int... values) Create a new big-endian buffer that holds a sequence of the specified 16-bit integers. | |
| directBuffer | back to summary |
|---|---|
| public static ByteBuf directBuffer() Creates a new big-endian direct buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand. | |
| directBuffer | back to summary |
|---|---|
| public static ByteBuf directBuffer(int initialCapacity) Creates a new big-endian direct buffer with the specified | |
| directBuffer | back to summary |
|---|---|
| public static ByteBuf directBuffer(int initialCapacity, int maxCapacity) Creates a new big-endian direct buffer with the specified
| |
| unmodifiableBuffer | back to summary |
|---|---|
| public static ByteBuf unmodifiableBuffer(ByteBuf buffer)
Deprecated Use Creates a read-only buffer which disallows any modification operations
on the specified
| |
| unmodifiableBuffer | back to summary |
|---|---|
| public static ByteBuf unmodifiableBuffer(ByteBuf... buffers)
Deprecated Wrap the given
| |
| unreleasableBuffer | back to summary |
|---|---|
| public static ByteBuf unreleasableBuffer(ByteBuf buf) Return a unreleasable view on the given | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(byte[] array) Creates a new big-endian buffer which wraps the specified | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(byte[] array, int offset, int length) Creates a new big-endian buffer which wraps the sub-region of the
specified | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(ByteBuffer buffer) Creates a new buffer which wraps the specified NIO buffer's current slice. A modification on the specified buffer's content will be visible to the returned buffer. | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(long memoryAddress, int size, boolean doFree) Creates a new buffer which wraps the specified memory address. If | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(ByteBuf buffer) Creates a new buffer which wraps the specified buffer's readable bytes. A modification on the specified buffer's content will be visible to the returned buffer. | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(byte[]... arrays) Creates a new big-endian composite buffer which wraps the specified arrays without copying them. A modification on the specified arrays' content will be visible to the returned buffer. | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(ByteBuf... buffers) Creates a new big-endian composite buffer which wraps the readable bytes of the specified buffers without copying them. A modification on the content of the specified buffers will be visible to the returned buffer. | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(ByteBuffer... buffers) Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them. A modification on the content of the specified buffers will be visible to the returned buffer. | |
| wrappedBuffer | back to summary |
|---|---|
| pack-priv static <T> ByteBuf wrappedBuffer(int maxNumComponents, CompositeByteBuf. | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(int maxNumComponents, byte[]... arrays) Creates a new big-endian composite buffer which wraps the specified arrays without copying them. A modification on the specified arrays' content will be visible to the returned buffer. | |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(int maxNumComponents, ByteBuf... buffers) Creates a new big-endian composite buffer which wraps the readable bytes of the specified buffers without copying them. A modification on the content of the specified buffers will be visible to the returned buffer.
| |
| wrappedBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedBuffer(int maxNumComponents, ByteBuffer... buffers) Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them. A modification on the content of the specified buffers will be visible to the returned buffer. | |
| wrappedUnmodifiableBuffer | back to summary |
|---|---|
| public static ByteBuf wrappedUnmodifiableBuffer(ByteBuf... buffers) Wrap the given | |
| wrappedUnmodifiableBuffer | back to summary |
|---|---|
| private static ByteBuf wrappedUnmodifiableBuffer(boolean copy, ByteBuf... buffers) | |