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>
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.}-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedUnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, boolean slice, ByteBuffer initialBuffer, int maxCapacity) Creates a new direct ByteBuf by wrapping the specified initial buffer.UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity) Creates a new direct buffer.protectedUnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, ByteBuffer initialBuffer, int maxCapacity) Creates a new direct buffer by wrapping the specified initial buffer. -
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) copy(int index, int length) Returns a copy of this buffer's sub-region.bytegetByte(int index) Gets a byte at the specified absoluteindexin this buffer.Transfers this buffer's data to the specified destination starting at the specified absoluteindex.intgetInt(int index) Gets a 32-bit integer at the specified absoluteindexin this buffer.longgetLong(int index) Gets a 64-bit long integer at the specified absoluteindexin this buffer.shortgetShort(int index) Gets a 16-bit short integer at the specified absoluteindexin this buffer.intgetUnsignedMedium(int index) Gets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer.booleanReturnstrueif and only if this buffer has a reference to the low-level memory address that points to the backing data.longReturns the low-level memory address that point to the first byte of ths backing data.protected SwappedByteBufCreates a newSwappedByteBuffor thisByteBufinstance.setByte(int index, int value) Sets the specified byte at the specified absoluteindexin this buffer.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.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.setInt(int index, int value) Sets the specified 32-bit integer at the specified absoluteindexin this buffer.setLong(int index, long value) Sets the specified 64-bit long integer at the specified absoluteindexin this buffer.setMedium(int index, int value) Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer.setShort(int index, int value) Sets the specified 16-bit short integer at the specified absoluteindexin 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 currentwriterIndexand increases thewriterIndexby the specifiedlength.Methods inherited from class UnpooledDirectByteBuf
alloc, allocateDirect, allocateDirectBuffer, array, arrayOffset, capacity, capacity, deallocate, freeDirect, getBytes, getBytes, getBytes, getBytes, getBytes, getIntLE, getLongLE, getShortLE, hasArray, internalNioBuffer, isContiguous, isDirect, nioBuffer, nioBufferCount, nioBuffers, order, readBytes, readBytes, readBytes, readBytes, readBytes, setBytes, setBytes, setIntLE, setLongLE, setMediumLE, setShortLE, unwrapMethods inherited from class AbstractReferenceCountedByteBuf
refCnt, release, release, resetRefCnt, retain, retain, setRefCnt, touch, touchMethods inherited from class 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, getMedium, getMediumLE, 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, readString, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedMedium, readUnsignedMediumLE, readUnsignedShort, readUnsignedShortLE, resetReaderIndex, resetWriterIndex, retainedDuplicate, retainedSlice, retainedSlice, setBoolean, setBytes, setBytes, setBytes, setChar, setCharSequence, setDouble, setFloat, setIndex, 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, writeShortLEMethods inherited from class ByteBuf
asByteBuf, getDoubleLE, getFloatLE, maxFastWritableBytes, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
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
@UnstableApi protected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, boolean slice, ByteBuffer initialBuffer, int maxCapacity) Creates a new direct ByteBuf by wrapping the specified initial buffer. Allows subclasses to control if initialBuffer.slice() should be invoked. Attention: this is a dangerous API and should only be used by someone who really knows the possible consequences. It allows to disable a protective slicing for the provided ByteBuffer instance and can cause sharing of this ByteBuffer instance between several UnpooledUnsafeDirectByteBuf objects, as a result modifications would be racy and unsafe.- Parameters:
slice- true means slice() should be called for the provided initialBuffermaxCapacity- the maximum capacity of the underlying direct buffer
-
-
Method Details
-
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.- Overrides:
hasMemoryAddressin classUnpooledDirectByteBuf
-
memoryAddress
public long memoryAddress()Description copied from class:ByteBufReturns the low-level memory address that point to the first byte of ths backing data.- Overrides:
memoryAddressin classUnpooledDirectByteBuf
-
getByte
public byte getByte(int index) Description copied from class:ByteBufGets a byte at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
getBytein classUnpooledDirectByteBuf
-
_getByte
protected byte _getByte(int index) - Overrides:
_getBytein classUnpooledDirectByteBuf
-
getShort
public short getShort(int index) Description copied from class:ByteBufGets a 16-bit short integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
getShortin classUnpooledDirectByteBuf
-
_getShort
protected short _getShort(int index) - Overrides:
_getShortin classUnpooledDirectByteBuf
-
_getShortLE
protected short _getShortLE(int index) - Overrides:
_getShortLEin classUnpooledDirectByteBuf
-
getUnsignedMedium
public int getUnsignedMedium(int index) Description copied from class:ByteBufGets an unsigned 24-bit medium integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
getUnsignedMediumin classUnpooledDirectByteBuf
-
_getUnsignedMedium
protected int _getUnsignedMedium(int index) - Overrides:
_getUnsignedMediumin classUnpooledDirectByteBuf
-
_getUnsignedMediumLE
protected int _getUnsignedMediumLE(int index) - Overrides:
_getUnsignedMediumLEin classUnpooledDirectByteBuf
-
getInt
public int getInt(int index) Description copied from class:ByteBufGets a 32-bit integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
getIntin classUnpooledDirectByteBuf
-
_getInt
protected int _getInt(int index) - Overrides:
_getIntin classUnpooledDirectByteBuf
-
_getIntLE
protected int _getIntLE(int index) - Overrides:
_getIntLEin classUnpooledDirectByteBuf
-
getLong
public long getLong(int index) Description copied from class:ByteBufGets a 64-bit long integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
getLongin classUnpooledDirectByteBuf
-
_getLong
protected long _getLong(int index) - Overrides:
_getLongin classUnpooledDirectByteBuf
-
_getLongLE
protected long _getLongLE(int index) - Overrides:
_getLongLEin classUnpooledDirectByteBuf
-
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.- Overrides:
getBytesin classUnpooledDirectByteBuf- Parameters:
dstIndex- the first index of the destinationlength- the number of bytes to transfer
-
setByte
Description copied from class:ByteBufSets the specified byte at the specified absoluteindexin this buffer. The 24 high-order bits of the specified value are ignored. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setBytein classUnpooledDirectByteBuf
-
_setByte
protected void _setByte(int index, int value) - Overrides:
_setBytein classUnpooledDirectByteBuf
-
setShort
Description copied from class:ByteBufSets the specified 16-bit short integer at the specified absoluteindexin this buffer. The 16 high-order bits of the specified value are ignored. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setShortin classUnpooledDirectByteBuf
-
_setShort
protected void _setShort(int index, int value) - Overrides:
_setShortin classUnpooledDirectByteBuf
-
_setShortLE
protected void _setShortLE(int index, int value) - Overrides:
_setShortLEin classUnpooledDirectByteBuf
-
setMedium
Description copied from class:ByteBufSets the specified 24-bit medium integer at the specified absoluteindexin this buffer. Please note that the most significant byte is ignored in the specified value. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setMediumin classUnpooledDirectByteBuf
-
_setMedium
protected void _setMedium(int index, int value) - Overrides:
_setMediumin classUnpooledDirectByteBuf
-
_setMediumLE
protected void _setMediumLE(int index, int value) - Overrides:
_setMediumLEin classUnpooledDirectByteBuf
-
setInt
Description copied from class:ByteBufSets the specified 32-bit integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setIntin classUnpooledDirectByteBuf
-
_setInt
protected void _setInt(int index, int value) - Overrides:
_setIntin classUnpooledDirectByteBuf
-
_setIntLE
protected void _setIntLE(int index, int value) - Overrides:
_setIntLEin classUnpooledDirectByteBuf
-
setLong
Description copied from class:ByteBufSets the specified 64-bit long integer at the specified absoluteindexin this buffer. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setLongin classUnpooledDirectByteBuf
-
_setLong
protected void _setLong(int index, long value) - Overrides:
_setLongin classUnpooledDirectByteBuf
-
_setLongLE
protected void _setLongLE(int index, long value) - Overrides:
_setLongLEin classUnpooledDirectByteBuf
-
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.- Overrides:
setBytesin classUnpooledDirectByteBuf- Parameters:
srcIndex- the first index of the sourcelength- the number of bytes to transfer
-
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.- Overrides:
setBytesin classUnpooledDirectByteBuf
-
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.- Overrides:
setBytesin classUnpooledDirectByteBuf
-
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.- Overrides:
setBytesin classUnpooledDirectByteBuf- 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
-
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.- Overrides:
copyin classUnpooledDirectByteBuf
-
newSwappedByteBuf
Description copied from class:AbstractByteBufCreates a newSwappedByteBuffor thisByteBufinstance.- Overrides:
newSwappedByteBufin classAbstractByteBuf
-
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
-