Package io.netty.buffer
Class UnpooledUnsafeDirectByteBuf
java.lang.Object
io.netty.buffer.ByteBuf
io.netty.buffer.AbstractByteBuf
io.netty.buffer.AbstractReferenceCountedByteBuf
io.netty.buffer.UnpooledDirectByteBuf
io.netty.buffer.UnpooledUnsafeDirectByteBuf
- All Implemented Interfaces:
ByteBufConvertible
,ReferenceCounted
,Comparable<ByteBuf>
- Direct Known Subclasses:
ByteBufUtil.ThreadLocalUnsafeDirectByteBuf
,UnpooledByteBufAllocator.InstrumentedUnpooledUnsafeDirectByteBuf
,UnpooledUnsafeNoCleanerDirectByteBuf
,WrappedUnpooledUnsafeDirectByteBuf
A NIO
ByteBuffer
based buffer. It is recommended to use
AbstractByteBufAllocator.directBuffer(int, int)
, Unpooled.directBuffer(int)
and
Unpooled.wrappedBuffer(ByteBuffer)
instead of calling the constructor explicitly.}-
Field Summary
FieldsFields inherited from class io.netty.buffer.UnpooledDirectByteBuf
buffer
Fields inherited from class io.netty.buffer.AbstractByteBuf
checkAccessible, leakDetector, readerIndex, writerIndex
-
Constructor Summary
ConstructorsModifierConstructorDescriptionUnpooledUnsafeDirectByteBuf
(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) Creates a new direct buffer.protected
UnpooledUnsafeDirectByteBuf
(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) Creates a new direct buffer by wrapping the specified initial buffer.(package private)
UnpooledUnsafeDirectByteBuf
(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity, boolean doFree) -
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) (package private) final long
addr
(int index) copy
(int index, int length) Returns a copy of this buffer's sub-region.byte
getByte
(int index) Gets a byte at the specified absoluteindex
in this buffer.(package private) void
getBytes
(int index, byte[] dst, int dstIndex, int length, boolean internal) Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.(package private) void
getBytes
(int index, OutputStream out, int length, boolean internal) (package private) void
getBytes
(int index, ByteBuffer dst, boolean internal) int
getInt
(int index) Gets a 32-bit integer at the specified absoluteindex
in this buffer.long
getLong
(int index) Gets a 64-bit long integer at the specified absoluteindex
in this buffer.short
getShort
(int index) Gets a 16-bit short integer at the specified absoluteindex
in this buffer.int
getUnsignedMedium
(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer.boolean
Returnstrue
if and only if this buffer has a reference to the low-level memory address that points to the backing data.long
Returns the low-level memory address that point to the first byte of ths backing data.protected SwappedByteBuf
Creates a newSwappedByteBuf
for thisByteBuf
instance.setByte
(int index, int value) Sets the specified byte at the specified absoluteindex
in this buffer.(package private) final void
setByteBuffer
(ByteBuffer buffer, boolean tryFree) setBytes
(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
.int
setBytes
(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 absoluteindex
until the source buffer's position reaches its limit.setInt
(int index, int value) Sets the specified 32-bit integer at the specified absoluteindex
in this buffer.setLong
(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindex
in this buffer.setMedium
(int index, int value) Sets the specified 24-bit medium integer at the specified absoluteindex
in this buffer.setShort
(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindex
in this buffer.setZero
(int index, int length) Fills this buffer with NUL (0x00) starting at the specified absoluteindex
.writeZero
(int length) Fills this buffer with NUL (0x00) starting at the currentwriterIndex
and increases thewriterIndex
by the specifiedlength
.Methods inherited from class io.netty.buffer.UnpooledDirectByteBuf
alloc, allocateDirect, array, arrayOffset, capacity, capacity, deallocate, freeDirect, getBytes, getBytes, getBytes, getBytes, getBytes, hasArray, internalNioBuffer, isContiguous, isDirect, nioBuffer, nioBufferCount, nioBuffers, order, readBytes, readBytes, readBytes, readBytes, readBytes, setBytes, setBytes, unwrap
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, discardReadBytes, discardSomeReadBytes, duplicate, ensureAccessible, ensureWritable, ensureWritable, ensureWritable0, equals, forEachByte, forEachByte, forEachByteAsc0, forEachByteDesc, forEachByteDesc, forEachByteDesc0, getBoolean, getBytes, getBytes, getBytes, getChar, getCharSequence, getDouble, getFloat, getIntLE, getLongLE, getMedium, getMediumLE, getShortLE, getUnsignedByte, getUnsignedInt, getUnsignedIntLE, getUnsignedMediumLE, getUnsignedShort, getUnsignedShortLE, hashCode, indexOf, isReadable, isReadable, isReadOnly, isWritable, isWritable, markReaderIndex, markWriterIndex, maxCapacity, maxCapacity, maxWritableBytes, nioBuffer, nioBuffers, order, readableBytes, readBoolean, readByte, 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, 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
Methods inherited from class io.netty.buffer.ByteBuf
asByteBuf, getDoubleLE, getFloatLE, maxFastWritableBytes, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
Field Details
-
memoryAddress
long memoryAddress
-
-
Constructor Details
-
UnpooledUnsafeDirectByteBuf
Creates a new direct buffer.- Parameters:
initialCapacity
- the initial capacity of the underlying direct buffermaxCapacity
- the maximum capacity of the underlying direct buffer
-
UnpooledUnsafeDirectByteBuf
protected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) Creates a new direct buffer by wrapping the specified initial buffer.- Parameters:
maxCapacity
- the maximum capacity of the underlying direct buffer
-
UnpooledUnsafeDirectByteBuf
UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity, boolean doFree)
-
-
Method Details
-
setByteBuffer
- Overrides:
setByteBuffer
in classUnpooledDirectByteBuf
-
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.- Overrides:
hasMemoryAddress
in classUnpooledDirectByteBuf
-
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.- Overrides:
memoryAddress
in classUnpooledDirectByteBuf
-
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 classUnpooledDirectByteBuf
-
_getByte
protected byte _getByte(int index) - Overrides:
_getByte
in classUnpooledDirectByteBuf
-
getShort
public short getShort(int index) Description copied from class:ByteBuf
Gets a 16-bit short integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
getShort
in classUnpooledDirectByteBuf
-
_getShort
protected short _getShort(int index) - Overrides:
_getShort
in classUnpooledDirectByteBuf
-
_getShortLE
protected short _getShortLE(int index) - Overrides:
_getShortLE
in classUnpooledDirectByteBuf
-
getUnsignedMedium
public int getUnsignedMedium(int index) Description copied from class:ByteBuf
Gets an unsigned 24-bit medium integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
getUnsignedMedium
in classUnpooledDirectByteBuf
-
_getUnsignedMedium
protected int _getUnsignedMedium(int index) - Overrides:
_getUnsignedMedium
in classUnpooledDirectByteBuf
-
_getUnsignedMediumLE
protected int _getUnsignedMediumLE(int index) - Overrides:
_getUnsignedMediumLE
in classUnpooledDirectByteBuf
-
getInt
public int getInt(int index) Description copied from class:ByteBuf
Gets a 32-bit integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
getInt
in classUnpooledDirectByteBuf
-
_getInt
protected int _getInt(int index) - Overrides:
_getInt
in classUnpooledDirectByteBuf
-
_getIntLE
protected int _getIntLE(int index) - Overrides:
_getIntLE
in classUnpooledDirectByteBuf
-
getLong
public long getLong(int index) Description copied from class:ByteBuf
Gets a 64-bit long integer at the specified absoluteindex
in this buffer. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
getLong
in classUnpooledDirectByteBuf
-
_getLong
protected long _getLong(int index) - Overrides:
_getLong
in classUnpooledDirectByteBuf
-
_getLongLE
protected long _getLongLE(int index) - Overrides:
_getLongLE
in classUnpooledDirectByteBuf
-
getBytes
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.- Overrides:
getBytes
in classUnpooledDirectByteBuf
- Parameters:
dstIndex
- the first index of the destinationlength
- the number of bytes to transfer
-
getBytes
void getBytes(int index, byte[] dst, int dstIndex, int length, boolean internal) - Overrides:
getBytes
in classUnpooledDirectByteBuf
-
getBytes
- Overrides:
getBytes
in classUnpooledDirectByteBuf
-
setByte
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 classUnpooledDirectByteBuf
-
_setByte
protected void _setByte(int index, int value) - Overrides:
_setByte
in classUnpooledDirectByteBuf
-
setShort
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 classUnpooledDirectByteBuf
-
_setShort
protected void _setShort(int index, int value) - Overrides:
_setShort
in classUnpooledDirectByteBuf
-
_setShortLE
protected void _setShortLE(int index, int value) - Overrides:
_setShortLE
in classUnpooledDirectByteBuf
-
setMedium
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 classUnpooledDirectByteBuf
-
_setMedium
protected void _setMedium(int index, int value) - Overrides:
_setMedium
in classUnpooledDirectByteBuf
-
_setMediumLE
protected void _setMediumLE(int index, int value) - Overrides:
_setMediumLE
in classUnpooledDirectByteBuf
-
setInt
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 classUnpooledDirectByteBuf
-
_setInt
protected void _setInt(int index, int value) - Overrides:
_setInt
in classUnpooledDirectByteBuf
-
_setIntLE
protected void _setIntLE(int index, int value) - Overrides:
_setIntLE
in classUnpooledDirectByteBuf
-
setLong
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 classUnpooledDirectByteBuf
-
_setLong
protected void _setLong(int index, long value) - Overrides:
_setLong
in classUnpooledDirectByteBuf
-
_setLongLE
protected void _setLongLE(int index, long value) - Overrides:
_setLongLE
in classUnpooledDirectByteBuf
-
setBytes
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
- Parameters:
srcIndex
- the first index of the sourcelength
- the number of bytes to transfer
-
setBytes
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
-
setBytes
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
-
getBytes
- Overrides:
getBytes
in classUnpooledDirectByteBuf
- Throws:
IOException
-
setBytes
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
- Parameters:
length
- the number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1
if the specifiedInputStream
reached EOF. - Throws:
IOException
- if the specified stream threw an exception during I/O
-
copy
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.- Overrides:
copy
in classUnpooledDirectByteBuf
-
addr
final long addr(int index) -
newSwappedByteBuf
Description copied from class:AbstractByteBuf
Creates a newSwappedByteBuf
for thisByteBuf
instance.- Overrides:
newSwappedByteBuf
in classAbstractByteBuf
-
setZero
Description copied from class:ByteBuf
Fills this buffer with NUL (0x00) starting at the specified absoluteindex
. This method does not modifyreaderIndex
orwriterIndex
of this buffer.- Overrides:
setZero
in classAbstractByteBuf
- Parameters:
length
- the number of NULs to write to the buffer
-
writeZero
Description copied from class:ByteBuf
Fills this buffer with NUL (0x00) starting at the currentwriterIndex
and increases thewriterIndex
by the specifiedlength
. Ifthis.writableBytes
is less thanlength
,ByteBuf.ensureWritable(int)
will be called in an attempt to expand capacity to accommodate.- Overrides:
writeZero
in classAbstractByteBuf
- Parameters:
length
- the number of NULs to write to the buffer
-