Top Fields Constructors Methods
io.netty.buffer

pack-priv abstract Class PooledByteBuf<T>

extends AbstractReferenceCountedByteBuf
Class Inheritance
Known Direct Subclasses
io.netty.buffer.PooledDirectByteBuf, io.netty.buffer.PooledHeapByteBuf, io.netty.buffer.PooledUnsafeDirectByteBuf
Imports
io.netty.util.Recycler.EnhancedHandle, io.netty.util.internal.ObjectPool.Handle, java.io.IOException, java.nio.ByteBuffer, .ByteOrder, java.nio.channels.ClosedChannelException, .FileChannel, .GatheringByteChannel, .ScatteringByteChannel

Field Summary

Modifier and TypeField and Description
private ByteBufAllocator
pack-priv PoolThreadCache
protected PoolChunk<T>
protected long
protected int
pack-priv int
protected T
protected int
private final Recycler.EnhancedHandle<PooledByteBuf<T>>
pack-priv ByteBuffer

Constructor Summary

AccessConstructor and Description
protected
PooledByteBuf(ObjectPool.Handle<? extends PooledByteBuf<T>> recyclerHandle, int maxCapacity)

Method Summary

Modifier and TypeMethod and Description
pack-priv final ByteBuffer
_internalNioBuffer(int index, int length, boolean duplicate)

public final ByteBufAllocator
alloc()

Implements abstract io.netty.buffer.ByteBuf.alloc.

Returns the ByteBufAllocator which created this buffer.
public final int
capacity()

Implements abstract io.netty.buffer.ByteBuf.capacity.

Returns the number of bytes (octets) this buffer can contain.
public final ByteBuf
capacity(int newCapacity)

Implements abstract io.netty.buffer.ByteBuf.capacity.

Adjusts the capacity of this buffer.
protected final void
pack-priv ByteBuffer
duplicateInternalNioBuffer(int index, int length)

public final int
getBytes(int index, GatheringByteChannel out, int
the maximum number of bytes to transfer
length
)

Implements abstract io.netty.buffer.ByteBuf.getBytes.

Transfers this buffer's data to the specified channel starting at the specified absolute index.
public final int
getBytes(int index, FileChannel out, long
the file position at which the transfer is to begin
position
,
int
the maximum number of bytes to transfer
length
)

Implements abstract io.netty.buffer.ByteBuf.getBytes.

Transfers this buffer's data starting at the specified absolute index to the specified channel starting at the given file position.
protected final int
idx(int index)

pack-priv void
init(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache)

private void
init0(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache)

pack-priv void
initUnpooled(PoolChunk<T> chunk, int length)

protected final ByteBuffer
public final ByteBuffer
internalNioBuffer(int index, int length)

Implements abstract io.netty.buffer.ByteBuf.internalNioBuffer.

Internal use only: Exposes the internal NIO buffer.
public final boolean
isContiguous()

Overrides io.netty.buffer.ByteBuf.isContiguous.

Returns true if this ByteBuf implementation is backed by a single memory region.
public int
maxFastWritableBytes()

Overrides io.netty.buffer.ByteBuf.maxFastWritableBytes.

Returns the maximum number of bytes which can be written for certain without involving an internal reallocation or data-copy.
protected abstract ByteBuffer
public final ByteBuffer
nioBuffer(int index, int length)

Implements abstract io.netty.buffer.ByteBuf.nioBuffer.

Exposes this buffer's sub-region as an NIO ByteBuffer.
public final int
nioBufferCount()

Implements abstract io.netty.buffer.ByteBuf.nioBufferCount.

Returns the maximum number of NIO ByteBuffers that consist this buffer.
public final ByteBuffer[]
nioBuffers(int index, int length)

Implements abstract io.netty.buffer.ByteBuf.nioBuffers.

Exposes this buffer's bytes as an NIO 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.
public final ByteOrder
order()

Implements abstract io.netty.buffer.ByteBuf.order.

Returns the endianness of this buffer.
public final int
readBytes(GatheringByteChannel out, int
the maximum number of bytes to transfer
length
)

Overrides io.netty.buffer.AbstractByteBuf.readBytes.

Transfers this buffer's data to the specified stream starting at the current readerIndex.
public final int
readBytes(FileChannel out, long
the file position at which the transfer is to begin
position
,
int
the maximum number of bytes to transfer
length
)

Overrides io.netty.buffer.AbstractByteBuf.readBytes.

Transfers this buffer's data starting at the current readerIndex to the specified channel starting at the given file position.
public final ByteBuf
retainedDuplicate()

Overrides io.netty.buffer.AbstractByteBuf.retainedDuplicate.

Returns a retained buffer which shares the whole region of this buffer.
public final ByteBuf
retainedSlice()

Overrides io.netty.buffer.AbstractByteBuf.retainedSlice.

Returns a retained slice of this buffer's readable bytes.
public final ByteBuf
retainedSlice(int index, int length)

Overrides io.netty.buffer.AbstractByteBuf.retainedSlice.

Returns a retained slice of this buffer's sub-region.
pack-priv final void
reuse(int maxCapacity)

Method must be called before reuse this PooledByteBufAllocator

public final int
setBytes(int index, ScatteringByteChannel in, int
the maximum number of bytes to transfer
length
)

Implements abstract io.netty.buffer.ByteBuf.setBytes.

Transfers the content of the specified source channel to this buffer starting at the specified absolute index.
public final int
setBytes(int index, FileChannel in, long
the file position at which the transfer is to begin
position
,
int
the maximum number of bytes to transfer
length
)

Implements abstract io.netty.buffer.ByteBuf.setBytes.

Transfers the content of the specified source channel starting at the given file position to this buffer starting at the specified absolute index.
public final ByteBuf
unwrap()

Implements abstract io.netty.buffer.ByteBuf.unwrap.

Return the underlying buffer instance if this buffer is a wrapper of another buffer.
Inherited from io.netty.buffer.AbstractReferenceCountedByteBuf:
isAccessiblerefCntreleasereleaseresetRefCntretainretainsetRefCnttouchtouch

Field Detail

allocatorback to summary
private ByteBufAllocator allocator
cacheback to summary
pack-priv PoolThreadCache cache
chunkback to summary
protected PoolChunk<T> chunk
handleback to summary
protected long handle
lengthback to summary
protected int length
maxLengthback to summary
pack-priv int maxLength
memoryback to summary
protected T memory
offsetback to summary
protected int offset
recyclerHandleback to summary
private final Recycler.EnhancedHandle<PooledByteBuf<T>> recyclerHandle
tmpNioBufback to summary
pack-priv ByteBuffer tmpNioBuf

Constructor Detail

PooledByteBufback to summary
protected PooledByteBuf(ObjectPool.Handle<? extends PooledByteBuf<T>> recyclerHandle, int maxCapacity)
Annotations
@SuppressWarnings:unchecked

Method Detail

_internalNioBufferback to summary
pack-priv final ByteBuffer _internalNioBuffer(int index, int length, boolean duplicate)
allocback to summary
public final ByteBufAllocator alloc()

Implements abstract io.netty.buffer.ByteBuf.alloc.

Doc from io.netty.buffer.ByteBuf.alloc.

Returns the ByteBufAllocator which created this buffer.

Annotations
@Override
capacityback to summary
public final int capacity()

Implements abstract io.netty.buffer.ByteBuf.capacity.

Doc from io.netty.buffer.ByteBuf.capacity.

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

Annotations
@Override
capacityback to summary
public final ByteBuf capacity(int newCapacity)

Implements abstract io.netty.buffer.ByteBuf.capacity.

Doc from io.netty.buffer.ByteBuf.capacity.

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

Annotations
@Override
deallocateback to summary
protected final void deallocate()

Implements abstract io.netty.buffer.AbstractReferenceCountedByteBuf.deallocate.

Doc from io.netty.buffer.AbstractReferenceCountedByteBuf.deallocate.

Called once refCnt() is equals 0.

Annotations
@Override
duplicateInternalNioBufferback to summary
pack-priv ByteBuffer duplicateInternalNioBuffer(int index, int length)
getBytesback to summary
public final int getBytes(int index, GatheringByteChannel out, int length) throws IOException

Implements abstract io.netty.buffer.ByteBuf.getBytes.

Doc from io.netty.buffer.ByteBuf.getBytes.

Transfers this buffer's data to the specified channel starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.

Parameters
length:int

the maximum number of bytes to transfer

Returns:int

the actual number of bytes written out to the specified channel

Annotations
@Override
Exceptions
IOException:
if the specified channel threw an exception during I/O
getBytesback to summary
public final int getBytes(int index, FileChannel out, long position, int length) throws IOException

Implements abstract io.netty.buffer.ByteBuf.getBytes.

Doc from io.netty.buffer.ByteBuf.getBytes.

Transfers this buffer's data starting at the specified absolute index to the specified channel starting at the given file position. This method does not modify readerIndex or writerIndex of this buffer. This method does not modify the channel's position.

Parameters
position:long

the file position at which the transfer is to begin

length:int

the maximum number of bytes to transfer

Returns:int

the actual number of bytes written out to the specified channel

Annotations
@Override
Exceptions
IOException:
if the specified channel threw an exception during I/O
idxback to summary
protected final int idx(int index)
initback to summary
pack-priv void init(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache)
init0back to summary
private void init0(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache)
initUnpooledback to summary
pack-priv void initUnpooled(PoolChunk<T> chunk, int length)
internalNioBufferback to summary
protected final ByteBuffer internalNioBuffer()
internalNioBufferback to summary
public final ByteBuffer internalNioBuffer(int index, int length)

Implements abstract io.netty.buffer.ByteBuf.internalNioBuffer.

Doc from io.netty.buffer.ByteBuf.internalNioBuffer.

Internal use only: Exposes the internal NIO buffer.

Annotations
@Override
isContiguousback to summary
public final boolean isContiguous()

Overrides io.netty.buffer.ByteBuf.isContiguous.

Doc from io.netty.buffer.ByteBuf.isContiguous.

Returns true if this ByteBuf implementation is backed by a single memory region. Composite buffer implementations must return false even if they currently hold ≤ 1 components. For buffers that return true, it's guaranteed that a successful call to discardReadBytes() will increase the value of maxFastWritableBytes() by the current readerIndex.

This method will return false by default, and a false return value does not necessarily mean that the implementation is composite or that it is not backed by a single memory region.

Annotations
@Override
maxFastWritableBytesback to summary
public int maxFastWritableBytes()

Overrides io.netty.buffer.ByteBuf.maxFastWritableBytes.

Doc from io.netty.buffer.ByteBuf.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 ≥ writableBytes() and ≤ maxWritableBytes().

Annotations
@Override
newInternalNioBufferback to summary
protected abstract ByteBuffer newInternalNioBuffer(T memory)
nioBufferback to summary
public final ByteBuffer nioBuffer(int index, int length)

Implements abstract io.netty.buffer.ByteBuf.nioBuffer.

Doc from io.netty.buffer.ByteBuf.nioBuffer.

Exposes this buffer's sub-region as an NIO 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 readerIndex or 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.

Annotations
@Override
nioBufferCountback to summary
public final int nioBufferCount()

Implements abstract io.netty.buffer.ByteBuf.nioBufferCount.

Doc from io.netty.buffer.ByteBuf.nioBufferCount.

Returns the maximum number of NIO ByteBuffers that consist this buffer. Note that nioBuffers() or nioBuffers(int, int) might return a less number of ByteBuffers.

Returns:int

-1 if this buffer has no underlying ByteBuffer. the number of the underlying ByteBuffers if this buffer has at least one underlying ByteBuffer. Note that this method does not return 0 to avoid confusion.

Annotations
@Override
nioBuffersback to summary
public final ByteBuffer[] nioBuffers(int index, int length)

Implements abstract io.netty.buffer.ByteBuf.nioBuffers.

Doc from io.netty.buffer.ByteBuf.nioBuffers.

Exposes this buffer's bytes as an NIO 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 readerIndex or 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.

Annotations
@Override
orderback to summary
public final ByteOrder order()

Implements abstract io.netty.buffer.ByteBuf.order.

Doc from io.netty.buffer.ByteBuf.order.

Returns the endianness of this buffer.

Annotations
@Override
readBytesback to summary
public final int readBytes(GatheringByteChannel out, int length) throws IOException

Overrides io.netty.buffer.AbstractByteBuf.readBytes.

Doc from io.netty.buffer.ByteBuf.readBytes.

Transfers this buffer's data to the specified stream starting at the current readerIndex.

Parameters
length:int

the maximum number of bytes to transfer

Returns:int

the actual number of bytes written out to the specified channel

Annotations
@Override
Exceptions
IOException:
if the specified channel threw an exception during I/O
readBytesback to summary
public final int readBytes(FileChannel out, long position, int length) throws IOException

Overrides io.netty.buffer.AbstractByteBuf.readBytes.

Doc from io.netty.buffer.ByteBuf.readBytes.

Transfers this buffer's data starting at the current readerIndex to the specified channel starting at the given file position. This method does not modify the channel's position.

Parameters
position:long

the file position at which the transfer is to begin

length:int

the maximum number of bytes to transfer

Returns:int

the actual number of bytes written out to the specified channel

Annotations
@Override
Exceptions
IOException:
if the specified channel threw an exception during I/O
retainedDuplicateback to summary
public final ByteBuf retainedDuplicate()

Overrides io.netty.buffer.AbstractByteBuf.retainedDuplicate.

Doc from io.netty.buffer.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 buf.slice(0, buf.capacity()). This method does not modify readerIndex or writerIndex of this buffer.

Note that this method returns a retained buffer unlike slice(int, int). This method behaves similarly to duplicate().retain() except that this method may return a buffer implementation that produces less garbage.

Annotations
@Override
retainedSliceback to summary
public final ByteBuf retainedSlice()

Overrides io.netty.buffer.AbstractByteBuf.retainedSlice.

Doc from io.netty.buffer.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 buf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer.

Note that this method returns a retained buffer unlike slice(). This method behaves similarly to slice().retain() except that this method may return a buffer implementation that produces less garbage.

Annotations
@Override
retainedSliceback to summary
public final ByteBuf retainedSlice(int index, int length)

Overrides io.netty.buffer.AbstractByteBuf.retainedSlice.

Doc from io.netty.buffer.ByteBuf.retainedSlice.

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 readerIndex or writerIndex of this buffer.

Note that this method returns a retained buffer unlike slice(int, int). This method behaves similarly to slice(...).retain() except that this method may return a buffer implementation that produces less garbage.

Annotations
@Override
reuseback to summary
pack-priv final void reuse(int maxCapacity)

Method must be called before reuse this PooledByteBufAllocator

setBytesback to summary
public final int setBytes(int index, ScatteringByteChannel in, int length) throws IOException

Implements abstract io.netty.buffer.ByteBuf.setBytes.

Doc from io.netty.buffer.ByteBuf.setBytes.

Transfers the content of the specified source channel to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer.

Parameters
length:int

the maximum number of bytes to transfer

Returns:int

the actual number of bytes read in from the specified channel. -1 if the specified channel is closed or it reached EOF.

Annotations
@Override
Exceptions
IOException:
if the specified channel threw an exception during I/O
setBytesback to summary
public final int setBytes(int index, FileChannel in, long position, int length) throws IOException

Implements abstract io.netty.buffer.ByteBuf.setBytes.

Doc from io.netty.buffer.ByteBuf.setBytes.

Transfers the content of the specified source channel starting at the given file position to this buffer starting at the specified absolute index. This method does not modify readerIndex or writerIndex of this buffer. This method does not modify the channel's position.

Parameters
position:long

the file position at which the transfer is to begin

length:int

the maximum number of bytes to transfer

Returns:int

the actual number of bytes read in from the specified channel. -1 if the specified channel is closed or it reached EOF.

Annotations
@Override
Exceptions
IOException:
if the specified channel threw an exception during I/O
unwrapback to summary
public final ByteBuf unwrap()

Implements abstract io.netty.buffer.ByteBuf.unwrap.

Doc from io.netty.buffer.ByteBuf.unwrap.

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

Returns:ByteBuf

null if this buffer is not a wrapper

Annotations
@Override