Package io.netty.buffer
Class FixedCompositeByteBuf
- java.lang.Object
-
- io.netty.buffer.ByteBuf
-
- io.netty.buffer.AbstractByteBuf
-
- io.netty.buffer.AbstractReferenceCountedByteBuf
-
- io.netty.buffer.FixedCompositeByteBuf
-
- All Implemented Interfaces:
ByteBufConvertible
,ReferenceCounted
,java.lang.Comparable<ByteBuf>
final class FixedCompositeByteBuf extends AbstractReferenceCountedByteBuf
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FixedCompositeByteBuf.Component
-
Field Summary
Fields Modifier and Type Field Description private ByteBufAllocator
allocator
private ByteBuf[]
buffers
private int
capacity
private boolean
direct
private static ByteBuf[]
EMPTY
private int
nioBufferCount
private java.nio.ByteOrder
order
-
Fields inherited from class io.netty.buffer.AbstractByteBuf
checkAccessible, leakDetector, readerIndex, writerIndex
-
-
Constructor Summary
Constructors Constructor Description FixedCompositeByteBuf(ByteBufAllocator allocator, ByteBuf... buffers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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)
ByteBufAllocator
alloc()
Returns theByteBufAllocator
which created this buffer.byte[]
array()
Returns the backing byte array of this buffer.int
arrayOffset()
Returns the offset of the first byte within the backing byte array of this buffer.private ByteBuf
buffer(int i)
Return theByteBuf
stored at the given index of the array.int
capacity()
Returns the number of bytes (octets) this buffer can contain.ByteBuf
capacity(int newCapacity)
Adjusts the capacity of this buffer.ByteBuf
copy(int index, int length)
Returns a copy of this buffer's sub-region.protected void
deallocate()
Called onceAbstractReferenceCountedByteBuf.refCnt()
is equals 0.ByteBuf
discardReadBytes()
Discards the bytes between the 0th index andreaderIndex
.private FixedCompositeByteBuf.Component
findComponent(int index)
byte
getByte(int index)
Gets a byte at the specified absoluteindex
in this buffer.ByteBuf
getBytes(int index, byte[] dst, int dstIndex, int length)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.ByteBuf
getBytes(int index, ByteBuf dst, int dstIndex, int length)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.ByteBuf
getBytes(int index, java.io.OutputStream out, int length)
Transfers this buffer's data to the specified stream starting at the specified absoluteindex
.ByteBuf
getBytes(int index, java.nio.ByteBuffer dst)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination's position reaches its limit.int
getBytes(int index, java.nio.channels.FileChannel out, long position, int length)
Transfers this buffer's data starting at the specified absoluteindex
to the specified channel starting at the given file position.int
getBytes(int index, java.nio.channels.GatheringByteChannel out, int length)
Transfers this buffer's data to the specified channel starting at the specified absoluteindex
.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.java.nio.ByteBuffer
internalNioBuffer(int index, int length)
Internal use only: Exposes the internal NIO buffer.boolean
isDirect()
Returnstrue
if and only if this buffer is backed by an NIO direct buffer.boolean
isWritable()
Returnstrue
if and only if(this.capacity - this.writerIndex)
is greater than0
.boolean
isWritable(int size)
Returnstrue
if and only if this buffer has enough room to allow writing the specified number of elements.int
maxCapacity()
Returns the maximum allowed capacity of this buffer.long
memoryAddress()
Returns the low-level memory address that point to the first byte of ths backing data.java.nio.ByteBuffer
nioBuffer(int index, int length)
Exposes this buffer's sub-region as an NIOByteBuffer
.int
nioBufferCount()
Returns the maximum number of NIOByteBuffer
s that consist this buffer.java.nio.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.java.nio.ByteOrder
order()
Returns the endianness of this buffer.ByteBuf
setByte(int index, int value)
Sets the specified byte at the specified absoluteindex
in this buffer.ByteBuf
setBytes(int index, byte[] src, int srcIndex, int length)
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
.ByteBuf
setBytes(int index, ByteBuf src, int srcIndex, int length)
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
.int
setBytes(int index, java.io.InputStream in, int length)
Transfers the content of the specified source stream to this buffer starting at the specified absoluteindex
.ByteBuf
setBytes(int index, java.nio.ByteBuffer src)
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer's position reaches its limit.int
setBytes(int index, java.nio.channels.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
.int
setBytes(int index, java.nio.channels.ScatteringByteChannel in, int length)
Transfers the content of the specified source channel to this buffer starting at the specified absoluteindex
.ByteBuf
setInt(int index, int value)
Sets the specified 32-bit integer at the specified absoluteindex
in this buffer.ByteBuf
setLong(int index, long value)
Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer.ByteBuf
setMedium(int index, int value)
Sets the specified 24-bit medium integer at the specified absoluteindex
in this buffer.ByteBuf
setShort(int index, int value)
Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer.java.lang.String
toString()
Returns the string representation of this buffer.ByteBuf
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
adjustMarkers, asReadOnly, bytesBefore, bytesBefore, bytesBefore, checkDstIndex, checkDstIndex, checkIndex, checkIndex, checkIndex0, checkNewCapacity, checkReadableBytes, checkSrcIndex, clear, compareTo, copy, discardMarks, discardSomeReadBytes, duplicate, ensureAccessible, ensureWritable, ensureWritable, ensureWritable0, equals, forEachByte, forEachByte, forEachByteAsc0, forEachByteDesc, forEachByteDesc, forEachByteDesc0, getBoolean, 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, markReaderIndex, markWriterIndex, 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, setBytes, setBytes, setBytes, setChar, setCharSequence, setDouble, setFloat, setIndex, setIndex0, setIntLE, setLongLE, setMediumLE, setShortLE, setZero, skipBytes, slice, slice, 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
asByteBuf, getDoubleLE, getFloatLE, isContiguous, maxFastWritableBytes, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
-
-
-
Field Detail
-
EMPTY
private static final ByteBuf[] EMPTY
-
nioBufferCount
private final int nioBufferCount
-
capacity
private final int capacity
-
allocator
private final ByteBufAllocator allocator
-
order
private final java.nio.ByteOrder order
-
buffers
private final ByteBuf[] buffers
-
direct
private final boolean direct
-
-
Constructor Detail
-
FixedCompositeByteBuf
FixedCompositeByteBuf(ByteBufAllocator allocator, ByteBuf... buffers)
-
-
Method Detail
-
isWritable
public boolean isWritable()
Description copied from class:ByteBuf
Returnstrue
if and only if(this.capacity - this.writerIndex)
is greater than0
.- Overrides:
isWritable
in classAbstractByteBuf
-
isWritable
public boolean isWritable(int size)
Description copied from class:ByteBuf
Returnstrue
if and only if this buffer has enough room to allow writing the specified number of elements.- Overrides:
isWritable
in classAbstractByteBuf
-
discardReadBytes
public ByteBuf discardReadBytes()
Description copied from class:ByteBuf
Discards the bytes between the 0th index andreaderIndex
. It moves the bytes betweenreaderIndex
andwriterIndex
to the 0th index, and setsreaderIndex
andwriterIndex
to0
andoldWriterIndex - oldReaderIndex
respectively.Please refer to the class documentation for more detailed explanation.
- Overrides:
discardReadBytes
in classAbstractByteBuf
-
setBytes
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length)
Description copied from class:ByteBuf
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of both the source (i.e.this
) and the destination.
-
setBytes
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length)
Description copied from class:ByteBuf
Transfers the specified source array's data to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
setBytes
public ByteBuf setBytes(int index, java.nio.ByteBuffer src)
Description copied from class:ByteBuf
Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex
until the source buffer's position reaches its limit. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
setByte
public ByteBuf setByte(int index, int value)
Description copied from class:ByteBuf
Sets the specified byte at the specified absoluteindex
in this buffer. The 24 high-order bits of the specified value are ignored. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
setByte
in classAbstractByteBuf
-
_setByte
protected void _setByte(int index, int value)
- Specified by:
_setByte
in classAbstractByteBuf
-
setShort
public ByteBuf setShort(int index, int value)
Description copied from class:ByteBuf
Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
setShort
in classAbstractByteBuf
-
_setShort
protected void _setShort(int index, int value)
- Specified by:
_setShort
in classAbstractByteBuf
-
_setShortLE
protected void _setShortLE(int index, int value)
- Specified by:
_setShortLE
in classAbstractByteBuf
-
setMedium
public ByteBuf setMedium(int index, int value)
Description copied from class:ByteBuf
Sets the specified 24-bit medium integer at the specified absoluteindex
in this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
setMedium
in classAbstractByteBuf
-
_setMedium
protected void _setMedium(int index, int value)
- Specified by:
_setMedium
in classAbstractByteBuf
-
_setMediumLE
protected void _setMediumLE(int index, int value)
- Specified by:
_setMediumLE
in classAbstractByteBuf
-
setInt
public ByteBuf setInt(int index, int value)
Description copied from class:ByteBuf
Sets the specified 32-bit integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
setInt
in classAbstractByteBuf
-
_setInt
protected void _setInt(int index, int value)
- Specified by:
_setInt
in classAbstractByteBuf
-
_setIntLE
protected void _setIntLE(int index, int value)
- Specified by:
_setIntLE
in classAbstractByteBuf
-
setLong
public ByteBuf setLong(int index, long value)
Description copied from class:ByteBuf
Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
setLong
in classAbstractByteBuf
-
_setLong
protected void _setLong(int index, long value)
- Specified by:
_setLong
in classAbstractByteBuf
-
_setLongLE
protected void _setLongLE(int index, long value)
- Specified by:
_setLongLE
in classAbstractByteBuf
-
setBytes
public int setBytes(int index, java.io.InputStream in, int length)
Description copied from class:ByteBuf
Transfers the content of the specified source stream to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
setBytes
public int setBytes(int index, java.nio.channels.ScatteringByteChannel in, int length)
Description copied from class:ByteBuf
Transfers the content of the specified source channel to this buffer starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
setBytes
public int setBytes(int index, java.nio.channels.FileChannel in, long position, int length)
Description copied from class:ByteBuf
Transfers 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 modifyreaderIndex
orwriterIndex
of this buffer. This method does not modify the channel's position.
-
capacity
public int capacity()
Description copied from class:ByteBuf
Returns the number of bytes (octets) this buffer can contain.
-
maxCapacity
public int maxCapacity()
Description copied from class:ByteBuf
Returns the maximum allowed capacity of this buffer. This value provides an upper bound onByteBuf.capacity()
.- Overrides:
maxCapacity
in classAbstractByteBuf
-
capacity
public ByteBuf capacity(int newCapacity)
Description copied from class:ByteBuf
Adjusts the capacity of this buffer. If thenewCapacity
is less than the current capacity, the content of this buffer is truncated. If thenewCapacity
is greater than the current capacity, the buffer is appended with unspecified data whose length is(newCapacity - currentCapacity)
.
-
alloc
public ByteBufAllocator alloc()
Description copied from class:ByteBuf
Returns theByteBufAllocator
which created this buffer.
-
order
public java.nio.ByteOrder order()
Description copied from class:ByteBuf
Returns the endianness of this buffer.
-
unwrap
public ByteBuf unwrap()
Description copied from class:ByteBuf
Return the underlying buffer instance if this buffer is a wrapper of another buffer.
-
isDirect
public boolean isDirect()
Description copied from class:ByteBuf
Returnstrue
if and only if this buffer is backed by an NIO direct buffer.
-
findComponent
private FixedCompositeByteBuf.Component findComponent(int index)
-
getByte
public byte getByte(int index)
Description copied from class:ByteBuf
Gets a byte at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
getByte
in classAbstractByteBuf
-
_getByte
protected byte _getByte(int index)
- Specified by:
_getByte
in classAbstractByteBuf
-
_getShort
protected short _getShort(int index)
- Specified by:
_getShort
in classAbstractByteBuf
-
_getShortLE
protected short _getShortLE(int index)
- Specified by:
_getShortLE
in classAbstractByteBuf
-
_getUnsignedMedium
protected int _getUnsignedMedium(int index)
- Specified by:
_getUnsignedMedium
in classAbstractByteBuf
-
_getUnsignedMediumLE
protected int _getUnsignedMediumLE(int index)
- Specified by:
_getUnsignedMediumLE
in classAbstractByteBuf
-
_getInt
protected int _getInt(int index)
- Specified by:
_getInt
in classAbstractByteBuf
-
_getIntLE
protected int _getIntLE(int index)
- Specified by:
_getIntLE
in classAbstractByteBuf
-
_getLong
protected long _getLong(int index)
- Specified by:
_getLong
in classAbstractByteBuf
-
_getLongLE
protected long _getLongLE(int index)
- Specified by:
_getLongLE
in classAbstractByteBuf
-
getBytes
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length)
Description copied from class:ByteBuf
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
getBytes
public ByteBuf getBytes(int index, java.nio.ByteBuffer dst)
Description copied from class:ByteBuf
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
until the destination's position reaches its limit. This method does not modifyreaderIndex
orwriterIndex
of this buffer while the destination'sposition
will be increased.
-
getBytes
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length)
Description copied from class:ByteBuf
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of both the source (i.e.this
) and the destination.
-
getBytes
public int getBytes(int index, java.nio.channels.GatheringByteChannel out, int length) throws java.io.IOException
Description copied from class:ByteBuf
Transfers this buffer's data to the specified channel starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
getBytes
public int getBytes(int index, java.nio.channels.FileChannel out, long position, int length) throws java.io.IOException
Description copied from class:ByteBuf
Transfers this buffer's data starting at the specified absoluteindex
to the specified channel starting at the given file position. This method does not modifyreaderIndex
orwriterIndex
of this buffer. This method does not modify the channel's position.- Specified by:
getBytes
in classByteBuf
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:
java.io.IOException
- if the specified channel threw an exception during I/O
-
getBytes
public ByteBuf getBytes(int index, java.io.OutputStream out, int length) throws java.io.IOException
Description copied from class:ByteBuf
Transfers this buffer's data to the specified stream starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.
-
copy
public ByteBuf copy(int index, int length)
Description copied from class:ByteBuf
Returns 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 modifyreaderIndex
orwriterIndex
of this buffer.
-
nioBufferCount
public 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)
-
nioBuffer
public java.nio.ByteBuffer nioBuffer(int index, int length)
Description copied from class:ByteBuf
Exposes 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 modifyreaderIndex
orwriterIndex
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.- Specified by:
nioBuffer
in classByteBuf
- See Also:
ByteBuf.nioBufferCount()
,ByteBuf.nioBuffers()
,ByteBuf.nioBuffers(int, int)
-
internalNioBuffer
public 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
-
nioBuffers
public java.nio.ByteBuffer[] nioBuffers(int index, int length)
Description copied from class:ByteBuf
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. This method does not modifyreaderIndex
orwriterIndex
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.- Specified by:
nioBuffers
in classByteBuf
- See Also:
ByteBuf.nioBufferCount()
,ByteBuf.nioBuffer()
,ByteBuf.nioBuffer(int, int)
-
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.
-
arrayOffset
public int arrayOffset()
Description copied from class:ByteBuf
Returns the offset of the first byte within the backing byte array of this buffer.- Specified by:
arrayOffset
in classByteBuf
-
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
-
memoryAddress
public long memoryAddress()
Description copied from class:ByteBuf
Returns the low-level memory address that point to the first byte of ths backing data.- Specified by:
memoryAddress
in classByteBuf
-
deallocate
protected void deallocate()
Description copied from class:AbstractReferenceCountedByteBuf
Called onceAbstractReferenceCountedByteBuf.refCnt()
is equals 0.- Specified by:
deallocate
in classAbstractReferenceCountedByteBuf
-
toString
public java.lang.String toString()
Description copied from class:ByteBuf
Returns the string representation of this buffer. This method does not necessarily return the whole content of the buffer but returns the values of the key properties such asByteBuf.readerIndex()
,ByteBuf.writerIndex()
andByteBuf.capacity()
.- Overrides:
toString
in classAbstractByteBuf
-
-