Package io.netty.buffer
Class AbstractPooledDerivedByteBuf
- java.lang.Object
-
- io.netty.buffer.ByteBuf
-
- io.netty.buffer.AbstractByteBuf
-
- io.netty.buffer.AbstractReferenceCountedByteBuf
-
- io.netty.buffer.AbstractPooledDerivedByteBuf
-
- All Implemented Interfaces:
ReferenceCounted
,java.lang.Comparable<ByteBuf>
- Direct Known Subclasses:
PooledDuplicatedByteBuf
,PooledSlicedByteBuf
abstract class AbstractPooledDerivedByteBuf extends AbstractReferenceCountedByteBuf
Abstract base class for derivedByteBuf
implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AbstractPooledDerivedByteBuf.PooledNonRetainedDuplicateByteBuf
private static class
AbstractPooledDerivedByteBuf.PooledNonRetainedSlicedByteBuf
-
Field Summary
Fields Modifier and Type Field Description private ByteBuf
parent
Deallocations of a pooled derived buffer should always propagate through the entire chain of derived buffers.private ObjectPool.Handle<AbstractPooledDerivedByteBuf>
recyclerHandle
private AbstractByteBuf
rootParent
-
Fields inherited from class io.netty.buffer.AbstractByteBuf
checkAccessible, leakDetector, readerIndex, writerIndex
-
-
Constructor Summary
Constructors Constructor Description AbstractPooledDerivedByteBuf(ObjectPool.Handle<? extends AbstractPooledDerivedByteBuf> recyclerHandle)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ByteBufAllocator
alloc()
Returns theByteBufAllocator
which created this buffer.byte[]
array()
Returns the backing byte array of this buffer.protected void
deallocate()
Called onceAbstractReferenceCountedByteBuf.refCnt()
is equals 0.(package private) ByteBuf
duplicate0()
boolean
hasArray()
Returnstrue
if and only if this buffer has a backing byte array.boolean
hasMemoryAddress()
Returnstrue
if and only if this buffer has a reference to the low-level memory address that points to the backing data.(package private) <U extends AbstractPooledDerivedByteBuf>
Uinit(AbstractByteBuf unwrapped, ByteBuf wrapped, int readerIndex, int writerIndex, int maxCapacity)
java.nio.ByteBuffer
internalNioBuffer(int index, int length)
Internal use only: Exposes the internal NIO buffer.boolean
isContiguous()
Returnstrue
if thisByteBuf
implementation is backed by a single memory region.boolean
isDirect()
Returnstrue
if and only if this buffer is backed by an NIO direct buffer.boolean
isReadOnly()
Returnstrue
if and only if this buffer is read-only.int
nioBufferCount()
Returns the maximum number of NIOByteBuffer
s that consist this buffer.java.nio.ByteOrder
order()
Deprecated.(package private) void
parent(ByteBuf newParent)
ByteBuf
retainedSlice()
Returns a retained slice of this buffer's readable bytes.ByteBuf
slice(int index, int length)
Returns a slice of this buffer's sub-region.AbstractByteBuf
unwrap()
Return the underlying buffer instance if this buffer is a wrapper of another buffer.-
Methods inherited from class io.netty.buffer.AbstractReferenceCountedByteBuf
isAccessible, refCnt, release, release, resetRefCnt, retain, retain, setRefCnt, touch, touch
-
Methods inherited from class io.netty.buffer.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, isWritable, isWritable, markReaderIndex, markWriterIndex, maxCapacity, maxCapacity, maxWritableBytes, newSwappedByteBuf, nioBuffer, nioBuffers, order, readableBytes, readBoolean, readByte, readBytes, readBytes, 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, retainedDuplicate, retainedSlice, setBoolean, setByte, setBytes, setBytes, setBytes, setChar, setCharSequence, setDouble, setFloat, setIndex, setIndex0, setInt, setIntLE, setLong, setLongLE, setMedium, setMediumLE, setShort, setShortLE, setZero, skipBytes, 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, writeZero
-
Methods inherited from class io.netty.buffer.ByteBuf
arrayOffset, capacity, capacity, copy, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getDoubleLE, getFloatLE, maxFastWritableBytes, memoryAddress, nioBuffer, nioBuffers, readDoubleLE, readFloatLE, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
-
-
-
Field Detail
-
recyclerHandle
private final ObjectPool.Handle<AbstractPooledDerivedByteBuf> recyclerHandle
-
rootParent
private AbstractByteBuf rootParent
-
parent
private ByteBuf parent
Deallocations of a pooled derived buffer should always propagate through the entire chain of derived buffers. This is because each pooled derived buffer maintains its own reference count and we should respect each one. If deallocations cause a release of the "root parent" then then we may prematurely release the underlying content before all the derived buffers have been released.
-
-
Constructor Detail
-
AbstractPooledDerivedByteBuf
AbstractPooledDerivedByteBuf(ObjectPool.Handle<? extends AbstractPooledDerivedByteBuf> recyclerHandle)
-
-
Method Detail
-
parent
final void parent(ByteBuf newParent)
-
unwrap
public final AbstractByteBuf unwrap()
Description copied from class:ByteBuf
Return the underlying buffer instance if this buffer is a wrapper of another buffer.
-
init
final <U extends AbstractPooledDerivedByteBuf> U init(AbstractByteBuf unwrapped, ByteBuf wrapped, int readerIndex, int writerIndex, int maxCapacity)
-
deallocate
protected final void deallocate()
Description copied from class:AbstractReferenceCountedByteBuf
Called onceAbstractReferenceCountedByteBuf.refCnt()
is equals 0.- Specified by:
deallocate
in classAbstractReferenceCountedByteBuf
-
alloc
public final ByteBufAllocator alloc()
Description copied from class:ByteBuf
Returns theByteBufAllocator
which created this buffer.
-
order
@Deprecated public final java.nio.ByteOrder order()
Deprecated.Description copied from class:ByteBuf
Returns the endianness of this buffer.
-
isReadOnly
public boolean isReadOnly()
Description copied from class:ByteBuf
Returnstrue
if and only if this buffer is read-only.- Overrides:
isReadOnly
in classAbstractByteBuf
-
isDirect
public final boolean isDirect()
Description copied from class:ByteBuf
Returnstrue
if and only if this buffer is backed by an NIO direct buffer.
-
hasArray
public boolean hasArray()
Description copied from class:ByteBuf
Returnstrue
if and only if this buffer has a backing byte array. If this method returns true, you can safely callByteBuf.array()
andByteBuf.arrayOffset()
.
-
array
public byte[] array()
Description copied from class:ByteBuf
Returns the backing byte array of this buffer.
-
hasMemoryAddress
public boolean hasMemoryAddress()
Description copied from class:ByteBuf
Returnstrue
if and only if this buffer has a reference to the low-level memory address that points to the backing data.- Specified by:
hasMemoryAddress
in classByteBuf
-
isContiguous
public boolean isContiguous()
Description copied from class:ByteBuf
Returnstrue
if thisByteBuf
implementation 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
false
by default, and afalse
return value does not necessarily mean that the implementation is composite or that it is not backed by a single memory region.- Overrides:
isContiguous
in classByteBuf
-
nioBufferCount
public final int nioBufferCount()
Description copied from class:ByteBuf
Returns the maximum number of NIOByteBuffer
s that consist this buffer. Note thatByteBuf.nioBuffers()
orByteBuf.nioBuffers(int, int)
might return a less number ofByteBuffer
s.- Specified by:
nioBufferCount
in classByteBuf
- Returns:
-1
if this buffer has no underlyingByteBuffer
. the number of the underlyingByteBuffer
s if this buffer has at least one underlyingByteBuffer
. Note that this method does not return0
to avoid confusion.- See Also:
ByteBuf.nioBuffer()
,ByteBuf.nioBuffer(int, int)
,ByteBuf.nioBuffers()
,ByteBuf.nioBuffers(int, int)
-
internalNioBuffer
public final java.nio.ByteBuffer internalNioBuffer(int index, int length)
Description copied from class:ByteBuf
Internal use only: Exposes the internal NIO buffer.- Specified by:
internalNioBuffer
in classByteBuf
-
retainedSlice
public final ByteBuf retainedSlice()
Description copied from class:ByteBuf
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 tobuf.slice(buf.readerIndex(), buf.readableBytes())
. This method does not modifyreaderIndex
orwriterIndex
of 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:
retainedSlice
in classAbstractByteBuf
-
slice
public ByteBuf slice(int index, int length)
Description copied from class:ByteBuf
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 modifyreaderIndex
orwriterIndex
of this buffer.Also be aware that this method will NOT call
ByteBuf.retain()
and so the reference count will NOT be increased.- Overrides:
slice
in classAbstractByteBuf
-
duplicate0
final ByteBuf duplicate0()
-
-