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 NIOByteBufferbased 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 protectedUnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, boolean slice, java.nio.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, 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)ByteBufcopy(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.ByteBufgetBytes(int index, ByteBuf dst, int dstIndex, int length)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.booleanhasMemoryAddress()Returnstrueif and only if this buffer has a reference to the low-level memory address that points to the backing data.longmemoryAddress()Returns the low-level memory address that point to the first byte of ths backing data.protected SwappedByteBufnewSwappedByteBuf()Creates a newSwappedByteBuffor thisByteBufinstance.ByteBufsetByte(int index, int value)Sets the specified byte at the specified absoluteindexin this buffer.ByteBufsetBytes(int index, byte[] src, int srcIndex, int length)Transfers the specified source array's data to this buffer starting at the specified absoluteindex.ByteBufsetBytes(int index, ByteBuf src, int srcIndex, int length)Transfers the specified source buffer's data to this buffer starting at the specified absoluteindex.intsetBytes(int index, java.io.InputStream in, int length)Transfers the content of the specified source stream to this buffer starting at the specified absoluteindex.ByteBufsetBytes(int index, java.nio.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.ByteBufsetInt(int index, int value)Sets the specified 32-bit integer at the specified absoluteindexin this buffer.ByteBufsetLong(int index, long value)Sets the specified 64-bit long integer at the specified absoluteindexin this buffer.ByteBufsetMedium(int index, int value)Sets the specified 24-bit medium integer at the specified absoluteindexin this buffer.ByteBufsetShort(int index, int value)Sets the specified 16-bit short integer at the specified absoluteindexin this buffer.ByteBufsetZero(int index, int length)Fills this buffer with NUL (0x00) starting at the specified absoluteindex.ByteBufwriteZero(int length)Fills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.-
Methods inherited from class io.netty.buffer.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, 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, 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, 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
-
UnpooledUnsafeDirectByteBuf
@UnstableApi protected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, boolean slice, java.nio.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 Detail
-
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
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length)
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 classUnpooledDirectByteBufdstIndex- the first index of the destinationlength- the number of bytes to transfer
-
setByte
public ByteBuf setByte(int index, int value)
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
public ByteBuf setShort(int index, int value)
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
public ByteBuf setMedium(int index, int value)
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
public ByteBuf setInt(int index, int value)
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
public ByteBuf setLong(int index, long value)
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
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length)
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 classUnpooledDirectByteBufsrcIndex- 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: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
public ByteBuf setBytes(int index, java.nio.ByteBuffer src)
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
public int setBytes(int index, java.io.InputStream in, int length) throws java.io.IOExceptionDescription 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 classUnpooledDirectByteBuflength- the number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel.
-1if the specifiedInputStreamreached 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: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
protected SwappedByteBuf newSwappedByteBuf()
Description copied from class:AbstractByteBufCreates a newSwappedByteBuffor thisByteBufinstance.- Overrides:
newSwappedByteBufin classAbstractByteBuf
-
setZero
public ByteBuf setZero(int index, int length)
Description copied from class:ByteBufFills this buffer with NUL (0x00) starting at the specified absoluteindex. This method does not modifyreaderIndexorwriterIndexof this buffer.- Overrides:
setZeroin classAbstractByteBuflength- the number of NULs to write to the buffer
-
writeZero
public ByteBuf writeZero(int length)
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
-
-