Unpooled

Creates a new {@link ByteBuf} by allocating new space or by wrapping or copying existing byte arrays, byte buffers and a string.

<h3>Use static import</h3> This classes is intended to be used with Java 5 static import statement:

<pre> import static io.netty.buffer.{@link Unpooled}.*;

{@link ByteBuf} heapBuffer = buffer(128); {@link ByteBuf} directBuffer = directBuffer(256); {@link ByteBuf} wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]); {@link ByteBuf} copiedBuffer = copiedBuffer({@link ByteBuffer}.allocate(128)); </pre>

<h3>Allocating a new buffer</h3>

Three buffer types are provided out of the box.

<ul> <li>{@link #buffer(int)} allocates a new fixed-capacity heap buffer.</li> <li>{@link #directBuffer(int)} allocates a new fixed-capacity direct buffer.</li> </ul>

<h3>Creating a wrapped buffer</h3>

Wrapped buffer is a buffer which is a view of one or more existing byte arrays and byte buffers. Any changes in the content of the original array or buffer will be visible in the wrapped buffer. Various wrapper methods are provided and their name is all {@code 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.

<h3>Creating a copied buffer</h3>

Copied buffer is a deep copy of one or more existing byte arrays, byte buffers or a string. Unlike a wrapped buffer, there's no shared data between the original data and the copied buffer. Various copy methods are provided and their name is all {@code copiedBuffer()}. It is also convenient to use this operation to merge multiple buffers into one buffer.

final
class Unpooled {}

Members

Static functions

EMPTY_BUFFER
ByteBuf EMPTY_BUFFER()

A buffer whose capacity is {@code 0}.

buffer
ByteBuf buffer()

Creates a new big-endian heap buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand.

buffer
ByteBuf buffer(size_t initialCapacity)

Creates a new big-endian heap buffer with the specified {@code capacity}, which expands its capacity boundlessly on demand. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.

buffer
ByteBuf buffer(int initialCapacity, int maxCapacity)

Creates a new big-endian heap buffer with the specified {@code initialCapacity}, that may grow up to {@code maxCapacity} The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.

compositeBuffer
CompositeByteBuf compositeBuffer()

Returns a new big-endian composite buffer with no components.

compositeBuffer
CompositeByteBuf compositeBuffer(int maxNumComponents)

Returns a new big-endian composite buffer with no components.

copiedBuffer
ByteBuf copiedBuffer(byte[] array)

Creates a new big-endian buffer whose content is a copy of the specified {@code array}. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and {@code array.length} respectively.

copiedBuffer
ByteBuf copiedBuffer(byte[] array, int offset, int length)

Creates a new big-endian buffer whose content is a copy of the specified {@code array}'s sub-region. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the specified {@code length} respectively.

copiedBuffer
ByteBuf copiedBuffer(ByteBuffer buffer)

Creates a new buffer whose content is a copy of the specified {@code buffer}'s current slice. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and {@code buffer.remaining} respectively.

copiedBuffer
ByteBuf copiedBuffer(ByteBuf b)

Creates a new buffer whose content is a copy of the specified {@code buffer}'s readable bytes. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and {@code buffer.readableBytes} respectively.

copiedBuffer
ByteBuf copiedBuffer(byte[][] arrays)

Creates a new big-endian buffer whose content is a merged copy of the specified {@code arrays}. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the sum of all arrays' {@code length} respectively.

copiedBuffer
ByteBuf copiedBuffer(ByteBuf[] buffers)

Creates a new buffer whose content is a merged copy of the specified {@code buffers}' readable bytes. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the sum of all buffers' {@code readableBytes} respectively.

copiedBuffer
ByteBuf copiedBuffer(ByteBuffer[] buffers)

Creates a new buffer whose content is a merged copy of the specified {@code buffers}' slices. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the sum of all buffers' {@code remaining} respectively.

copiedBuffer
ByteBuf copiedBuffer(CharSequence data, Charset charset)

Creates a new big-endian buffer whose content is the specified {@code string} encoded in the specified {@code charset}. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the length of the encoded string respectively.

copiedBuffer
ByteBuf copiedBuffer(char[] array, Charset charset)

Creates a new big-endian buffer whose content is the specified {@code array} encoded in the specified {@code charset}. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the length of the encoded string respectively.

copiedBuffer
ByteBuf copiedBuffer(char[] array, size_t offset, size_t length, Charset charset)

Creates a new big-endian buffer whose content is a subregion of the specified {@code array} encoded in the specified {@code charset}. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0} and the length of the encoded string respectively.

copyBoolean
ByteBuf copyBoolean(bool value)

Creates a new single-byte big-endian buffer that holds the specified bool value.

copyBoolean
ByteBuf copyBoolean(bool[] values)

Create a new big-endian buffer that holds a sequence of the specified bool values.

copyDouble
ByteBuf copyDouble(double[] values)

Create a new big-endian buffer that holds a sequence of the specified 64-bit floating point numbers.

copyFloat
ByteBuf copyFloat(float[] values)

Create a new big-endian buffer that holds a sequence of the specified 32-bit floating point numbers.

copyInt
ByteBuf copyInt(int value)

Creates a new 4-byte big-endian buffer that holds the specified 32-bit integer.

copyInt
ByteBuf copyInt(int[] values)

Create a big-endian buffer that holds a sequence of the specified 32-bit integers.

copyLong
ByteBuf copyLong(long[] values)

Create a new big-endian buffer that holds a sequence of the specified 64-bit integers.

copyMedium
ByteBuf copyMedium(int value)

Creates a new 3-byte big-endian buffer that holds the specified 24-bit integer.

copyMedium
ByteBuf copyMedium(int[] values)

Create a new big-endian buffer that holds a sequence of the specified 24-bit integers.

copyShort
ByteBuf copyShort(int[] values)

Create a new big-endian buffer that holds a sequence of the specified 16-bit integers.

directBuffer
ByteBuf directBuffer()

Creates a new big-endian direct buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand.

directBuffer
ByteBuf directBuffer(size_t initialCapacity)

Creates a new big-endian direct buffer with the specified {@code capacity}, which expands its capacity boundlessly on demand. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.

directBuffer
ByteBuf directBuffer(int initialCapacity, int maxCapacity)

Creates a new big-endian direct buffer with the specified {@code initialCapacity}, that may grow up to {@code maxCapacity}. The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.

wrappedBuffer
ByteBuf wrappedBuffer(byte[] array)

Creates a new big-endian buffer which wraps the specified {@code array}. A modification on the specified array's content will be visible to the returned buffer.

wrappedBuffer
ByteBuf wrappedBuffer(byte[] array, int offset, int length)

Creates a new big-endian buffer which wraps the sub-region of the specified {@code array}. A modification on the specified array's content will be visible to the returned buffer.

wrappedBuffer
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
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. @param buffer The buffer to wrap. Reference count ownership of this variable is transferred to this method. @return The readable portion of the {@code buffer}, or an empty buffer if there is no readable portion. The caller is responsible for releasing this buffer.

wrappedBuffer
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
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. @param buffers The buffers to wrap. Reference count ownership of all variables is transferred to this method. @return The readable portion of the {@code buffers}. The caller is responsible for releasing this buffer.

wrappedBuffer
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
ByteBuf wrappedBuffer(int maxNumComponents, ByteWrapper!(T) wrapper, T[] array)
Undocumented in source. Be warned that the author may not have intended to support it.
wrappedBuffer
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
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. @param maxNumComponents Advisement as to how many independent buffers are allowed to exist before consolidation occurs. @param buffers The buffers to wrap. Reference count ownership of all variables is transferred to this method. @return The readable portion of the {@code buffers}. The caller is responsible for releasing this buffer.

wrappedBuffer
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
ByteBuf wrappedUnmodifiableBuffer(ByteBuf[] buffers)

Wrap the given {@link ByteBuf}s in an unmodifiable {@link ByteBuf}. Be aware the returned {@link ByteBuf} will not try to slice the given {@link ByteBuf}s to reduce GC-Pressure.

Variables

BIG_ENDIAN
enum ByteOrder BIG_ENDIAN;

Big endian byte order.

LITTLE_ENDIAN
enum ByteOrder LITTLE_ENDIAN;

Little endian byte order.

Meta