Class PooledByteBuf<T>
- All Implemented Interfaces:
ByteBufConvertible, ReferenceCounted, Comparable<ByteBuf>
- Direct Known Subclasses:
PooledDirectByteBuf, PooledHeapByteBuf, PooledUnsafeDirectByteBuf
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteBufAllocator(package private) PoolThreadCacheprotected longprotected int(package private) intprotected Tprotected intprivate final Recycler.EnhancedHandle<PooledByteBuf<T>> (package private) ByteBufferFields inherited from class AbstractByteBuf
checkAccessible, leakDetector, readerIndex, writerIndex -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPooledByteBuf(ObjectPool.Handle<? extends PooledByteBuf<T>> recyclerHandle, int maxCapacity) -
Method Summary
Modifier and TypeMethodDescription(package private) final ByteBuffer_internalNioBuffer(int index, int length, boolean duplicate) final ByteBufAllocatoralloc()Returns theByteBufAllocatorwhich created this buffer.final intcapacity()Returns the number of bytes (octets) this buffer can contain.final ByteBufcapacity(int newCapacity) Adjusts the capacity of this buffer.protected final voidCalled onceAbstractReferenceCountedByteBuf.refCnt()is equals 0.(package private) ByteBufferduplicateInternalNioBuffer(int index, int length) final intgetBytes(int index, FileChannel out, long position, int length) Transfers this buffer's data starting at the specified absoluteindexto the specified channel starting at the given file position.final intgetBytes(int index, GatheringByteChannel out, int length) Transfers this buffer's data to the specified channel starting at the specified absoluteindex.protected final intidx(int index) (package private) voidinit(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache) private voidinit0(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache) (package private) voidinitUnpooled(PoolChunk<T> chunk, int length) protected final ByteBufferfinal ByteBufferinternalNioBuffer(int index, int length) Internal use only: Exposes the internal NIO buffer.final booleanReturnstrueif thisByteBufimplementation is backed by a single memory region.intReturns the maximum number of bytes which can be written for certain without involving an internal reallocation or data-copy.protected abstract ByteBuffernewInternalNioBuffer(T memory) final ByteBuffernioBuffer(int index, int length) Exposes this buffer's sub-region as an NIOByteBuffer.final intReturns the maximum number of NIOByteBuffers that consist this buffer.final ByteBuffer[]nioBuffers(int index, int length) Exposes this buffer's bytes as an NIOByteBuffer'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.final ByteOrderorder()Returns the endianness of this buffer.final intreadBytes(FileChannel out, long position, int length) Transfers this buffer's data starting at the currentreaderIndexto the specified channel starting at the given file position.final intreadBytes(GatheringByteChannel out, int length) Transfers this buffer's data to the specified stream starting at the currentreaderIndex.final ByteBufReturns a retained buffer which shares the whole region of this buffer.final ByteBufReturns a retained slice of this buffer's readable bytes.final ByteBufretainedSlice(int index, int length) Returns a retained slice of this buffer's sub-region.(package private) final voidreuse(int maxCapacity) Method must be called before reuse thisPooledByteBufAllocatorfinal intsetBytes(int index, FileChannel in, long position, int length) Transfers the content of the specified source channel starting at the given file position to this buffer starting at the specified absoluteindex.final intsetBytes(int index, ScatteringByteChannel in, int length) Transfers the content of the specified source channel to this buffer starting at the specified absoluteindex.final ByteBufunwrap()Return the underlying buffer instance if this buffer is a wrapper of another buffer.Methods inherited from class AbstractReferenceCountedByteBuf
isAccessible, refCnt, release, release, resetRefCnt, retain, retain, setRefCnt, touch, touchMethods inherited from class AbstractByteBuf
_getByte, _getInt, _getIntLE, _getLong, _getLongLE, _getShort, _getShortLE, _getUnsignedMedium, _getUnsignedMediumLE, _setByte, _setInt, _setIntLE, _setLong, _setLongLE, _setMedium, _setMediumLE, _setShort, _setShortLE, adjustMarkers, asReadOnly, bytesBefore, bytesBefore, bytesBefore, checkDstIndex, checkDstIndex, checkIndex, checkIndex, checkIndex0, checkNewCapacity, checkReadableBytes, checkSrcIndex, clear, compareTo, copy, discardMarks, discardReadBytes, discardSomeReadBytes, duplicate, ensureAccessible, ensureWritable, ensureWritable, ensureWritable0, equals, forEachByte, forEachByte, forEachByteAsc0, forEachByteDesc, forEachByteDesc, forEachByteDesc0, getBoolean, getByte, getBytes, getBytes, getBytes, getChar, getCharSequence, getDouble, getFloat, getInt, getIntLE, getLong, getLongLE, getMedium, getMediumLE, getShort, getShortLE, getUnsignedByte, getUnsignedInt, getUnsignedIntLE, getUnsignedMedium, getUnsignedMediumLE, getUnsignedShort, getUnsignedShortLE, hashCode, indexOf, isReadable, isReadable, isReadOnly, isWritable, isWritable, markReaderIndex, markWriterIndex, maxCapacity, maxCapacity, maxWritableBytes, newSwappedByteBuf, nioBuffer, nioBuffers, order, readableBytes, readBoolean, readByte, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readChar, readCharSequence, readDouble, readerIndex, readerIndex, readFloat, readInt, readIntLE, readLong, readLongLE, readMedium, readMediumLE, readRetainedSlice, readShort, readShortLE, readSlice, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedMedium, readUnsignedMediumLE, readUnsignedShort, readUnsignedShortLE, resetReaderIndex, resetWriterIndex, setBoolean, setByte, setBytes, setBytes, setBytes, setChar, setCharSequence, setDouble, setFloat, setIndex, setIndex0, setInt, setIntLE, setLong, setLongLE, setMedium, setMediumLE, setShort, setShortLE, setZero, skipBytes, slice, slice, toString, toString, toString, trimIndicesToCapacity, writableBytes, writeBoolean, writeByte, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeChar, writeCharSequence, writeDouble, writeFloat, writeInt, writeIntLE, writeLong, writeLongLE, writeMedium, writeMediumLE, writerIndex, writerIndex, writeShort, writeShortLE, writeZeroMethods inherited from class ByteBuf
array, arrayOffset, asByteBuf, copy, getBytes, getBytes, getBytes, getBytes, getDoubleLE, getFloatLE, hasArray, hasMemoryAddress, isDirect, memoryAddress, readDoubleLE, readFloatLE, setBytes, setBytes, setBytes, setBytes, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
Field Details
-
recyclerHandle
-
chunk
-
handle
protected long handle -
memory
-
offset
protected int offset -
length
protected int length -
maxLength
int maxLength -
cache
PoolThreadCache cache -
tmpNioBuf
ByteBuffer tmpNioBuf -
allocator
-
-
Constructor Details
-
PooledByteBuf
protected PooledByteBuf(ObjectPool.Handle<? extends PooledByteBuf<T>> recyclerHandle, int maxCapacity)
-
-
Method Details
-
init
void init(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache) -
initUnpooled
-
init0
private void init0(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int offset, int length, int maxLength, PoolThreadCache cache) -
reuse
final void reuse(int maxCapacity) Method must be called before reuse thisPooledByteBufAllocator -
capacity
-
maxFastWritableBytes
public int maxFastWritableBytes()Description copied from class:ByteBufReturns the maximum number of bytes which can be written for certain without involving an internal reallocation or data-copy. The returned value will be ≥ByteBuf.writableBytes()and ≤ByteBuf.maxWritableBytes().- Overrides:
maxFastWritableBytesin classByteBuf
-
capacity
Description copied from class:ByteBufAdjusts the capacity of this buffer. If thenewCapacityis less than the current capacity, the content of this buffer is truncated. If thenewCapacityis greater than the current capacity, the buffer is appended with unspecified data whose length is(newCapacity - currentCapacity). -
alloc
Description copied from class:ByteBufReturns theByteBufAllocatorwhich created this buffer. -
order
Description copied from class:ByteBufReturns the endianness of this buffer. -
unwrap
-
retainedDuplicate
Description copied from class:ByteBufReturns 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 tobuf.slice(0, buf.capacity()). This method does not modifyreaderIndexorwriterIndexof this buffer.Note that this method returns a retained buffer unlike
ByteBuf.slice(int, int). This method behaves similarly toduplicate().retain()except that this method may return a buffer implementation that produces less garbage.- Overrides:
retainedDuplicatein classAbstractByteBuf
-
retainedSlice
Description copied from class:ByteBufReturns 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 tobuf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modifyreaderIndexorwriterIndexof this buffer.Note that this method returns a retained buffer unlike
ByteBuf.slice(). This method behaves similarly toslice().retain()except that this method may return a buffer implementation that produces less garbage.- Overrides:
retainedSlicein classAbstractByteBuf
-
retainedSlice
Description copied from class:ByteBufReturns 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 modifyreaderIndexorwriterIndexof this buffer.Note that this method returns a retained buffer unlike
ByteBuf.slice(int, int). This method behaves similarly toslice(...).retain()except that this method may return a buffer implementation that produces less garbage.- Overrides:
retainedSlicein classAbstractByteBuf
-
internalNioBuffer
-
newInternalNioBuffer
-
deallocate
protected final void deallocate()Description copied from class:AbstractReferenceCountedByteBufCalled onceAbstractReferenceCountedByteBuf.refCnt()is equals 0.- Specified by:
deallocatein classAbstractReferenceCountedByteBuf
-
idx
protected final int idx(int index) -
_internalNioBuffer
-
duplicateInternalNioBuffer
-
internalNioBuffer
Description copied from class:ByteBufInternal use only: Exposes the internal NIO buffer.- Specified by:
internalNioBufferin classByteBuf
-
nioBufferCount
public final int nioBufferCount()Description copied from class:ByteBufReturns the maximum number of NIOByteBuffers that consist this buffer. Note thatByteBuf.nioBuffers()orByteBuf.nioBuffers(int, int)might return a less number ofByteBuffers.- Specified by:
nioBufferCountin classByteBuf- Returns:
-1if this buffer has no underlyingByteBuffer. the number of the underlyingByteBuffers if this buffer has at least one underlyingByteBuffer. Note that this method does not return0to avoid confusion.- See Also:
-
nioBuffer
Description copied from class:ByteBufExposes this buffer's sub-region as an NIOByteBuffer. 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 modifyreaderIndexorwriterIndexof this buffer. Please note that the returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic buffer and it adjusted its capacity. -
nioBuffers
Description copied from class:ByteBufExposes this buffer's bytes as an NIOByteBuffer'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 modifyreaderIndexorwriterIndexof 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.- Specified by:
nioBuffersin classByteBuf- See Also:
-
isContiguous
public final boolean isContiguous()Description copied from class:ByteBufReturnstrueif thisByteBufimplementation is backed by a single memory region. Composite buffer implementations must return false even if they currently hold ≤ 1 components. For buffers that returntrue, it's guaranteed that a successful call toByteBuf.discardReadBytes()will increase the value ofByteBuf.maxFastWritableBytes()by the currentreaderIndex.This method will return
falseby default, and afalsereturn value does not necessarily mean that the implementation is composite or that it is not backed by a single memory region.- Overrides:
isContiguousin classByteBuf
-
getBytes
Description copied from class:ByteBufTransfers this buffer's data to the specified channel starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Specified by:
getBytesin classByteBuf- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IOException- if the specified channel threw an exception during I/O
-
readBytes
Description copied from class:ByteBufTransfers this buffer's data to the specified stream starting at the currentreaderIndex.- Overrides:
readBytesin classAbstractByteBuf- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IOException- if the specified channel threw an exception during I/O
-
getBytes
Description copied from class:ByteBufTransfers this buffer's data starting at the specified absoluteindexto the specified channel starting at the given file position. This method does not modifyreaderIndexorwriterIndexof this buffer. This method does not modify the channel's position.- Specified by:
getBytesin classByteBuf- Parameters:
position- the file position at which the transfer is to beginlength- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IOException- if the specified channel threw an exception during I/O
-
readBytes
Description copied from class:ByteBufTransfers this buffer's data starting at the currentreaderIndexto the specified channel starting at the given file position. This method does not modify the channel's position.- Overrides:
readBytesin classAbstractByteBuf- Parameters:
position- the file position at which the transfer is to beginlength- the maximum number of bytes to transfer- Returns:
- the actual number of bytes written out to the specified channel
- Throws:
IOException- if the specified channel threw an exception during I/O
-
setBytes
Description copied from class:ByteBufTransfers the content of the specified source channel to this buffer starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Specified by:
setBytesin classByteBuf- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1if the specified channel is closed or it reached EOF. - Throws:
IOException- if the specified channel threw an exception during I/O
-
setBytes
Description copied from class:ByteBufTransfers the content of the specified source channel starting at the given file position to this buffer starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer. This method does not modify the channel's position.- Specified by:
setBytesin classByteBuf- Parameters:
position- the file position at which the transfer is to beginlength- the maximum number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1if the specified channel is closed or it reached EOF. - Throws:
IOException- if the specified channel threw an exception during I/O
-