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
,java.lang.Comparable<ByteBuf>
public class UnpooledUnsafeDirectByteBuf extends UnpooledDirectByteBuf
A NIOByteBuffer
based buffer. It is recommended to useAbstractByteBufAllocator.directBuffer(int, int)
,Unpooled.directBuffer(int)
andUnpooled.wrappedBuffer(ByteBuffer)
instead of calling the constructor explicitly.}
-
-
Constructor Summary
Constructors Modifier Constructor Description UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity)
Creates a new direct buffer.protected
UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, java.nio.ByteBuffer initialBuffer, int maxCapacity)
Creates a new direct buffer by wrapping the specified initial buffer.
-
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)
ByteBuf
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.ByteBuf
getBytes(int index, ByteBuf dst, int dstIndex, int length)
Transfers this buffer's data to the specified destination starting at the specified absoluteindex
.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
hasMemoryAddress()
Returnstrue
if and only if this buffer has a reference to the low-level memory address that points to the backing data.long
memoryAddress()
Returns the low-level memory address that point to the first byte of ths backing data.protected SwappedByteBuf
newSwappedByteBuf()
Creates a newSwappedByteBuf
for thisByteBuf
instance.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.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.ByteBuf
setZero(int index, int length)
Fills this buffer with NUL (0x00) starting at the specified absoluteindex
.ByteBuf
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
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, checkNewCapacity, checkReadableBytes, checkSrcIndex, clear, compareTo, copy, discardReadBytes, discardSomeReadBytes, duplicate, ensureAccessible, ensureWritable, ensureWritable, equals, forEachByte, forEachByte, forEachByteDesc, forEachByteDesc, 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, 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
-
-
-
-
Constructor Detail
-
UnpooledUnsafeDirectByteBuf
public UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity)
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, java.nio.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
-
-
Method Detail
-
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
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.- Overrides:
getBytes
in classUnpooledDirectByteBuf
dstIndex
- the first index of the destinationlength
- the number of bytes to transfer
-
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 classUnpooledDirectByteBuf
-
_setByte
protected void _setByte(int index, int value)
- Overrides:
_setByte
in classUnpooledDirectByteBuf
-
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 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
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 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
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 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
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 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
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
srcIndex
- the first index of the sourcelength
- the number of bytes to transfer
-
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
-
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.- Overrides:
setBytes
in classUnpooledDirectByteBuf
-
setBytes
public int setBytes(int index, java.io.InputStream in, int length) throws java.io.IOException
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
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:
java.io.IOException
- if the specified stream threw an exception during I/O
-
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.- Overrides:
copy
in classUnpooledDirectByteBuf
-
newSwappedByteBuf
protected SwappedByteBuf newSwappedByteBuf()
Description copied from class:AbstractByteBuf
Creates a newSwappedByteBuf
for thisByteBuf
instance.- Overrides:
newSwappedByteBuf
in classAbstractByteBuf
-
setZero
public ByteBuf setZero(int index, int length)
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
length
- the number of NULs to write to the buffer
-
writeZero
public ByteBuf writeZero(int length)
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
-
-