Package io.netty.buffer
Class AdaptivePoolingAllocator.AdaptiveByteBuf
java.lang.Object
io.netty.buffer.ByteBuf
io.netty.buffer.AbstractByteBuf
io.netty.buffer.AbstractReferenceCountedByteBuf
io.netty.buffer.AdaptivePoolingAllocator.AdaptiveByteBuf
- All Implemented Interfaces:
ByteBufConvertible,ReferenceCounted,Comparable<ByteBuf>
- Enclosing class:
AdaptivePoolingAllocator
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) AdaptivePoolingAllocator.Chunkprivate final Recycler.EnhancedHandle<AdaptivePoolingAllocator.AdaptiveByteBuf> private booleanprivate booleanprivate intprivate intprivate AbstractByteBufprivate intprivate ByteBufferFields inherited from class io.netty.buffer.AbstractByteBuf
checkAccessible, leakDetector, readerIndex, writerIndex -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionprotected byte_getByte(int index) protected int_getInt(int index) protected int_getIntLE(int index) protected long_getLong(int index) protected long_getLongLE(int index) protected short_getShort(int index) protected short_getShortLE(int index) protected int_getUnsignedMedium(int index) protected int_getUnsignedMediumLE(int index) protected void_setByte(int index, int value) protected void_setInt(int index, int value) protected void_setIntLE(int index, int value) protected void_setLong(int index, long value) protected void_setLongLE(int index, long value) protected void_setMedium(int index, int value) protected void_setMediumLE(int index, int value) protected void_setShort(int index, int value) protected void_setShortLE(int index, int value) alloc()Returns theByteBufAllocatorwhich created this buffer.byte[]array()Returns the backing byte array of this buffer.intReturns the offset of the first byte within the backing byte array of this buffer.intcapacity()Returns the number of bytes (octets) this buffer can contain.capacity(int newCapacity) Adjusts the capacity of this buffer.copy(int index, int length) Returns a copy of this buffer's sub-region.protected voidCalled onceAbstractReferenceCountedByteBuf.refCnt()is equals 0.intforEachByte(int index, int length, ByteProcessor processor) Iterates over the specified area of this buffer with the specifiedprocessorin ascending order.intforEachByteDesc(int index, int length, ByteProcessor processor) Iterates over the specified area of this buffer with the specifiedprocessorin descending order.private intforEachResult(int ret) getBytes(int index, byte[] dst, int dstIndex, int length) Transfers this buffer's data to the specified destination starting at the specified absoluteindex.Transfers this buffer's data to the specified destination starting at the specified absoluteindex.getBytes(int index, OutputStream out, int length) Transfers this buffer's data to the specified stream starting at the specified absoluteindex.getBytes(int index, ByteBuffer dst) Transfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination's position reaches its limit.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.intgetBytes(int index, GatheringByteChannel out, int length) Transfers this buffer's data to the specified channel starting at the specified absoluteindex.booleanhasArray()Returnstrueif and only if this buffer has a backing byte array.booleanReturnstrueif and only if this buffer has a reference to the low-level memory address that points to the backing data.private intidx(int index) (package private) voidinit(AbstractByteBuf unwrapped, AdaptivePoolingAllocator.Chunk wrapped, int readerIndex, int writerIndex, int startIndex, int size, int capacity, int maxCapacity) private ByteBufferinternalNioBuffer(int index, int length) Internal use only: Exposes the internal NIO buffer.booleanReturnstrueif thisByteBufimplementation is backed by a single memory region.booleanisDirect()Returnstrueif and only if this buffer is backed by an NIO direct buffer.intReturns the maximum number of bytes which can be written for certain without involving an internal reallocation or data-copy.longReturns the low-level memory address that point to the first byte of ths backing data.nioBuffer(int index, int length) Exposes this buffer's sub-region as an NIOByteBuffer.intReturns the maximum number of NIOByteBuffers that consist this buffer.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.order()Returns the endianness of this buffer.private AbstractByteBufsetBytes(int index, byte[] src, int srcIndex, int length) Transfers the specified source array's data to this buffer starting at the specified absoluteindex.Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex.intsetBytes(int index, InputStream in, int length) Transfers the content of the specified source stream to this buffer starting at the specified absoluteindex.setBytes(int index, ByteBuffer src) Transfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer's position reaches its limit.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.intsetBytes(int index, ScatteringByteChannel in, int length) Transfers the content of the specified source channel to this buffer starting at the specified absoluteindex.intsetCharSequence(int index, CharSequence sequence, Charset charset) Writes the specifiedCharSequenceat the givenindex.private intsetCharSequence0(int index, CharSequence sequence, Charset charset, boolean expand) setZero(int index, int length) Fills this buffer with NUL (0x00) starting at the specified absoluteindex.unwrap()Return the underlying buffer instance if this buffer is a wrapper of another buffer.intwriteCharSequence(CharSequence sequence, Charset charset) Writes the specifiedCharSequenceat the currentwriterIndexand increases thewriterIndexby the written bytes.writeZero(int length) Fills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.Methods inherited from class io.netty.buffer.AbstractReferenceCountedByteBuf
isAccessible, refCnt, release, release, resetRefCnt, retain, retain, setRefCnt, touch, touchMethods inherited from class io.netty.buffer.AbstractByteBuf
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, forEachByteAsc0, 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, 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, retainedSlice, setBoolean, setByte, setBytes, setBytes, setBytes, setChar, setDouble, setFloat, setIndex, setIndex0, setInt, setIntLE, setLong, setLongLE, setMedium, setMediumLE, setShort, setShortLE, skipBytes, slice, slice, toString, toString, toString, trimIndicesToCapacity, writableBytes, writeBoolean, writeByte, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeChar, writeDouble, writeFloat, writeInt, writeIntLE, writeLong, writeLongLE, writeMedium, writeMediumLE, writerIndex, writerIndex, writeShort, writeShortLEMethods inherited from class io.netty.buffer.ByteBuf
asByteBuf, getDoubleLE, getFloatLE, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
Field Details
-
handle
-
startIndex
private int startIndex -
rootParent
-
chunk
-
length
private int length -
maxFastCapacity
private int maxFastCapacity -
tmpNioBuf
-
hasArray
private boolean hasArray -
hasMemoryAddress
private boolean hasMemoryAddress
-
-
Constructor Details
-
AdaptiveByteBuf
AdaptiveByteBuf(Recycler.EnhancedHandle<AdaptivePoolingAllocator.AdaptiveByteBuf> recyclerHandle)
-
-
Method Details
-
init
void init(AbstractByteBuf unwrapped, AdaptivePoolingAllocator.Chunk wrapped, int readerIndex, int writerIndex, int startIndex, int size, int capacity, int maxCapacity) -
rootParent
-
capacity
public int capacity()Description copied from class:ByteBufReturns the number of bytes (octets) this buffer can contain. -
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
Description copied from class:ByteBufReturn the underlying buffer instance if this buffer is a wrapper of another buffer. -
isDirect
public boolean isDirect()Description copied from class:ByteBufReturnstrueif and only if this buffer is backed by an NIO direct buffer. -
arrayOffset
public int arrayOffset()Description copied from class:ByteBufReturns the offset of the first byte within the backing byte array of this buffer.- Specified by:
arrayOffsetin classByteBuf
-
hasMemoryAddress
public boolean hasMemoryAddress()Description copied from class:ByteBufReturnstrueif and only if this buffer has a reference to the low-level memory address that points to the backing data.- Specified by:
hasMemoryAddressin classByteBuf
-
memoryAddress
public long memoryAddress()Description copied from class:ByteBufReturns the low-level memory address that point to the first byte of ths backing data.- Specified by:
memoryAddressin classByteBuf
-
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. -
internalNioBuffer
Description copied from class:ByteBufInternal use only: Exposes the internal NIO buffer.- Specified by:
internalNioBufferin classByteBuf
-
internalNioBuffer
-
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:
-
hasArray
public boolean hasArray()Description copied from class:ByteBufReturnstrueif 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:ByteBufReturns the backing byte array of this buffer. -
copy
Description copied from class:ByteBufReturns a copy of this buffer's sub-region. Modifying the content of the returned buffer or this buffer does not affect each other at all. This method does not modifyreaderIndexorwriterIndexof this buffer. -
nioBufferCount
public 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:
-
_getByte
protected byte _getByte(int index) - Specified by:
_getBytein classAbstractByteBuf
-
_getShort
protected short _getShort(int index) - Specified by:
_getShortin classAbstractByteBuf
-
_getShortLE
protected short _getShortLE(int index) - Specified by:
_getShortLEin classAbstractByteBuf
-
_getUnsignedMedium
protected int _getUnsignedMedium(int index) - Specified by:
_getUnsignedMediumin classAbstractByteBuf
-
_getUnsignedMediumLE
protected int _getUnsignedMediumLE(int index) - Specified by:
_getUnsignedMediumLEin classAbstractByteBuf
-
_getInt
protected int _getInt(int index) - Specified by:
_getIntin classAbstractByteBuf
-
_getIntLE
protected int _getIntLE(int index) - Specified by:
_getIntLEin classAbstractByteBuf
-
_getLong
protected long _getLong(int index) - Specified by:
_getLongin classAbstractByteBuf
-
_getLongLE
protected long _getLongLE(int index) - Specified by:
_getLongLEin classAbstractByteBuf
-
getBytes
Description copied from class:ByteBufTransfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof both the source (i.e.this) and the destination. -
getBytes
Description copied from class:ByteBufTransfers this buffer's data to the specified destination starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer. -
getBytes
Description copied from class:ByteBufTransfers this buffer's data to the specified destination starting at the specified absoluteindexuntil the destination's position reaches its limit. This method does not modifyreaderIndexorwriterIndexof this buffer while the destination'spositionwill be increased. -
_setByte
protected void _setByte(int index, int value) - Specified by:
_setBytein classAbstractByteBuf
-
_setShort
protected void _setShort(int index, int value) - Specified by:
_setShortin classAbstractByteBuf
-
_setShortLE
protected void _setShortLE(int index, int value) - Specified by:
_setShortLEin classAbstractByteBuf
-
_setMedium
protected void _setMedium(int index, int value) - Specified by:
_setMediumin classAbstractByteBuf
-
_setMediumLE
protected void _setMediumLE(int index, int value) - Specified by:
_setMediumLEin classAbstractByteBuf
-
_setInt
protected void _setInt(int index, int value) - Specified by:
_setIntin classAbstractByteBuf
-
_setIntLE
protected void _setIntLE(int index, int value) - Specified by:
_setIntLEin classAbstractByteBuf
-
_setLong
protected void _setLong(int index, long value) - Specified by:
_setLongin classAbstractByteBuf
-
_setLongLE
protected void _setLongLE(int index, long value) - Specified by:
_setLongLEin classAbstractByteBuf
-
setBytes
Description copied from class:ByteBufTransfers the specified source array's data to this buffer starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer. -
setBytes
Description copied from class:ByteBufTransfers the specified source buffer's data to this buffer starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof both the source (i.e.this) and the destination. -
setBytes
Description copied from class:ByteBufTransfers the specified source buffer's data to this buffer starting at the specified absoluteindexuntil the source buffer's position reaches its limit. This method does not modifyreaderIndexorwriterIndexof this buffer. -
getBytes
Description copied from class:ByteBufTransfers this buffer's data to the specified stream starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Specified by:
getBytesin classByteBuf- Parameters:
length- the number of bytes to transfer- Throws:
IOException- if the specified stream threw an exception during I/O
-
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
-
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
-
setBytes
Description copied from class:ByteBufTransfers the content of the specified source stream to this buffer starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Specified by:
setBytesin classByteBuf- Parameters:
length- the number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1if the specifiedInputStreamreached EOF. - Throws:
IOException- if the specified stream 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
-
setCharSequence
Description copied from class:ByteBufWrites the specifiedCharSequenceat the givenindex. ThewriterIndexis not modified by this method.- Overrides:
setCharSequencein classAbstractByteBuf- Parameters:
index- on which the sequence should be writtensequence- to writecharset- that should be used.- Returns:
- the written number of bytes.
-
setCharSequence0
-
writeCharSequence
Description copied from class:ByteBufWrites the specifiedCharSequenceat the currentwriterIndexand increases thewriterIndexby the written bytes. in this buffer. Ifthis.writableBytesis not large enough to write the whole sequence,ByteBuf.ensureWritable(int)will be called in an attempt to expand capacity to accommodate.- Overrides:
writeCharSequencein classAbstractByteBuf- Parameters:
sequence- to writecharset- that should be used- Returns:
- the written number of bytes
-
forEachByte
Description copied from class:ByteBufIterates over the specified area of this buffer with the specifiedprocessorin ascending order. (i.e.index,(index + 1), ..(index + length - 1))- Overrides:
forEachBytein classAbstractByteBuf- Returns:
-1if the processor iterated to or beyond the end of the specified area. The last-visited index If theByteProcessor.process(byte)returnedfalse.
-
forEachByteDesc
Description copied from class:ByteBufIterates over the specified area of this buffer with the specifiedprocessorin descending order. (i.e.(index + length - 1),(index + length - 2), ...index)- Overrides:
forEachByteDescin classAbstractByteBuf- Returns:
-1if the processor iterated to or beyond the beginning of the specified area. The last-visited index If theByteProcessor.process(byte)returnedfalse.
-
setZero
Description copied from class:ByteBufFills this buffer with NUL (0x00) starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setZeroin classAbstractByteBuf- Parameters:
length- the number of NULs to write to the buffer
-
writeZero
Description copied from class:ByteBufFills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength. Ifthis.writableBytesis less thanlength,ByteBuf.ensureWritable(int)will be called in an attempt to expand capacity to accommodate.- Overrides:
writeZeroin classAbstractByteBuf- Parameters:
length- the number of NULs to write to the buffer
-
forEachResult
private int forEachResult(int ret) -
isContiguous
public 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
-
idx
private int idx(int index) -
deallocate
protected void deallocate()Description copied from class:AbstractReferenceCountedByteBufCalled onceAbstractReferenceCountedByteBuf.refCnt()is equals 0.- Specified by:
deallocatein classAbstractReferenceCountedByteBuf
-