public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
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.}| 限定符 | 构造器和说明 |
|---|---|
protected |
UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc,
java.nio.ByteBuffer initialBuffer,
int maxCapacity)
Creates a new direct buffer by wrapping the specified initial buffer.
|
|
UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc,
int initialCapacity,
int maxCapacity)
Creates a new direct buffer.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected byte |
_getByte(int index) |
protected int |
_getInt(int index) |
protected long |
_getLong(int index) |
protected short |
_getShort(int index) |
protected int |
_getUnsignedMedium(int index) |
protected void |
_setByte(int index,
int value) |
protected void |
_setInt(int index,
int value) |
protected void |
_setLong(int index,
long value) |
protected void |
_setMedium(int index,
int value) |
protected void |
_setShort(int index,
int value) |
ByteBufAllocator |
alloc()
Returns the
ByteBufAllocator which created this buffer. |
protected java.nio.ByteBuffer |
allocateDirect(int initialCapacity)
Allocate a new direct
ByteBuffer with the given initialCapacity. |
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.
|
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 once
AbstractReferenceCountedByteBuf.refCnt() is equals 0. |
protected void |
freeDirect(java.nio.ByteBuffer buffer)
Free a direct
ByteBuffer |
ByteBuf |
getBytes(int index,
byte[] dst,
int dstIndex,
int length)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index. |
ByteBuf |
getBytes(int index,
java.nio.ByteBuffer dst)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index until the destination's position
reaches its limit. |
ByteBuf |
getBytes(int index,
ByteBuf dst,
int dstIndex,
int length)
Transfers this buffer's data to the specified destination starting at
the specified absolute
index. |
int |
getBytes(int index,
java.nio.channels.GatheringByteChannel out,
int length)
Transfers this buffer's data to the specified channel starting at the
specified absolute
index. |
ByteBuf |
getBytes(int index,
java.io.OutputStream out,
int length)
Transfers this buffer's data to the specified stream starting at the
specified absolute
index. |
boolean |
hasArray()
Returns
true if and only if this buffer has a backing byte array. |
boolean |
hasMemoryAddress()
Returns
true 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()
Returns
true if and only if this buffer is backed by an
NIO direct buffer. |
long |
memoryAddress()
Returns the low-level memory address that point to the first byte of ths backing data.
|
protected SwappedByteBuf |
newSwappedByteBuf()
Creates a new
SwappedByteBuf for this ByteBuf instance. |
java.nio.ByteBuffer |
nioBuffer(int index,
int length)
Exposes this buffer's sub-region as an NIO
ByteBuffer. |
int |
nioBufferCount()
Returns the maximum number of NIO
ByteBuffers that consist this buffer. |
java.nio.ByteBuffer[] |
nioBuffers(int index,
int length)
Exposes this buffer's bytes as an NIO
ByteBuffer'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 |
readBytes(java.nio.ByteBuffer dst)
Transfers this buffer's data to the specified destination starting at
the current
readerIndex until the destination's position
reaches its limit, and increases the readerIndex by the
number of the transferred bytes. |
int |
readBytes(java.nio.channels.GatheringByteChannel out,
int length)
Transfers this buffer's data to the specified stream starting at the
current
readerIndex. |
ByteBuf |
setBytes(int index,
byte[] src,
int srcIndex,
int length)
Transfers the specified source array's data to this buffer starting at
the specified absolute
index. |
ByteBuf |
setBytes(int index,
java.nio.ByteBuffer src)
Transfers the specified source buffer's data to this buffer starting at
the specified absolute
index until the source buffer's position
reaches its limit. |
ByteBuf |
setBytes(int index,
ByteBuf src,
int srcIndex,
int length)
Transfers the specified source buffer's data to this buffer starting at
the specified absolute
index. |
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 absolute
index. |
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 absolute
index. |
ByteBuf |
setZero(int index,
int length)
Fills this buffer with NUL (0x00) starting at the specified
absolute
index. |
ByteBuf |
unwrap()
Return the underlying buffer instance if this buffer is a wrapper of another buffer.
|
ByteBuf |
writeZero(int length)
Fills this buffer with NUL (0x00) starting at the current
writerIndex and increases the writerIndex by the
specified length. |
refCnt, release, release, retain, retain, setRefCntadjustMarkers, bytesBefore, bytesBefore, bytesBefore, checkDstIndex, checkIndex, checkIndex, checkNewCapacity, checkReadableBytes, checkSrcIndex, clear, compareTo, copy, discardReadBytes, discardSomeReadBytes, duplicate, ensureAccessible, ensureWritable, ensureWritable, equals, forEachByte, forEachByte, forEachByteDesc, forEachByteDesc, getBoolean, getByte, getBytes, getBytes, getBytes, getChar, getDouble, getFloat, getInt, getLong, getMedium, getShort, getUnsignedByte, getUnsignedInt, getUnsignedMedium, getUnsignedShort, hashCode, indexOf, isReadable, isReadable, isWritable, isWritable, markReaderIndex, markWriterIndex, maxCapacity, maxCapacity, maxWritableBytes, nioBuffer, nioBuffers, order, readableBytes, readBoolean, readByte, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readChar, readDouble, readerIndex, readerIndex, readFloat, readInt, readLong, readMedium, readShort, readSlice, readUnsignedByte, readUnsignedInt, readUnsignedMedium, readUnsignedShort, resetReaderIndex, resetWriterIndex, setBoolean, setByte, setBytes, setBytes, setBytes, setChar, setDouble, setFloat, setIndex, setInt, setLong, setMedium, setShort, skipBytes, slice, slice, toString, toString, toString, writableBytes, writeBoolean, writeByte, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeChar, writeDouble, writeFloat, writeInt, writeLong, writeMedium, writerIndex, writerIndex, writeShortpublic UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity)
initialCapacity - the initial capacity of the underlying direct buffermaxCapacity - the maximum capacity of the underlying direct bufferprotected UnpooledUnsafeDirectByteBuf(ByteBufAllocator alloc, java.nio.ByteBuffer initialBuffer, int maxCapacity)
maxCapacity - the maximum capacity of the underlying direct bufferprotected java.nio.ByteBuffer allocateDirect(int initialCapacity)
ByteBuffer with the given initialCapacity.protected void freeDirect(java.nio.ByteBuffer buffer)
ByteBufferpublic boolean isDirect()
ByteBuftrue if and only if this buffer is backed by an
NIO direct buffer.public int capacity()
ByteBufpublic ByteBuf capacity(int newCapacity)
ByteBufnewCapacity is less than the current
capacity, the content of this buffer is truncated. If the newCapacity is greater
than the current capacity, the buffer is appended with unspecified data whose length is
(newCapacity - currentCapacity).public ByteBufAllocator alloc()
ByteBufByteBufAllocator which created this buffer.public java.nio.ByteOrder order()
ByteBufpublic boolean hasArray()
ByteBuftrue if and only if this buffer has a backing byte array.
If this method returns true, you can safely call ByteBuf.array() and
ByteBuf.arrayOffset().public byte[] array()
ByteBufpublic int arrayOffset()
ByteBufarrayOffset 在类中 ByteBufpublic boolean hasMemoryAddress()
ByteBuftrue if and only if this buffer has a reference to the low-level memory address that points
to the backing data.hasMemoryAddress 在类中 ByteBufpublic long memoryAddress()
ByteBufmemoryAddress 在类中 ByteBufprotected byte _getByte(int index)
_getByte 在类中 AbstractByteBufprotected short _getShort(int index)
_getShort 在类中 AbstractByteBufprotected int _getUnsignedMedium(int index)
_getUnsignedMedium 在类中 AbstractByteBufprotected int _getInt(int index)
_getInt 在类中 AbstractByteBufprotected long _getLong(int index)
_getLong 在类中 AbstractByteBufpublic ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length)
ByteBufindex.
This method does not modify readerIndex or writerIndex
of both the source (i.e. this) and the destination.public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length)
ByteBufindex.
This method does not modify readerIndex or writerIndex
of this buffer.public ByteBuf getBytes(int index, java.nio.ByteBuffer dst)
ByteBufindex until the destination's position
reaches its limit.
This method does not modify readerIndex or writerIndex of
this buffer while the destination's position will be increased.public ByteBuf readBytes(java.nio.ByteBuffer dst)
ByteBufreaderIndex until the destination's position
reaches its limit, and increases the readerIndex by the
number of the transferred bytes.readBytes 在类中 AbstractByteBufprotected void _setByte(int index,
int value)
_setByte 在类中 AbstractByteBufprotected void _setShort(int index,
int value)
_setShort 在类中 AbstractByteBufprotected void _setMedium(int index,
int value)
_setMedium 在类中 AbstractByteBufprotected void _setInt(int index,
int value)
_setInt 在类中 AbstractByteBufprotected void _setLong(int index,
long value)
_setLong 在类中 AbstractByteBufpublic ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length)
ByteBufindex.
This method does not modify readerIndex or writerIndex
of both the source (i.e. this) and the destination.public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length)
ByteBufindex.
This method does not modify readerIndex or writerIndex of
this buffer.public ByteBuf setBytes(int index, java.nio.ByteBuffer src)
ByteBufindex until the source buffer's position
reaches its limit.
This method does not modify readerIndex or writerIndex of
this buffer.public ByteBuf getBytes(int index, java.io.OutputStream out, int length) throws java.io.IOException
ByteBufindex.
This method does not modify readerIndex or writerIndex of
this buffer.public int getBytes(int index,
java.nio.channels.GatheringByteChannel out,
int length)
throws java.io.IOException
ByteBufindex.
This method does not modify readerIndex or writerIndex of
this buffer.public int readBytes(java.nio.channels.GatheringByteChannel out,
int length)
throws java.io.IOException
ByteBufreaderIndex.readBytes 在类中 AbstractByteBuflength - the maximum number of bytes to transferjava.io.IOException - if the specified channel threw an exception during I/Opublic int setBytes(int index,
java.io.InputStream in,
int length)
throws java.io.IOException
ByteBufindex.
This method does not modify readerIndex or writerIndex of
this buffer.public int setBytes(int index,
java.nio.channels.ScatteringByteChannel in,
int length)
throws java.io.IOException
ByteBufindex.
This method does not modify readerIndex or writerIndex of
this buffer.public int nioBufferCount()
ByteBufByteBuffers that consist this buffer. Note that ByteBuf.nioBuffers()
or ByteBuf.nioBuffers(int, int) might return a less number of ByteBuffers.nioBufferCount 在类中 ByteBuf-1 if this buffer has no underlying ByteBuffer.
the number of the underlying ByteBuffers if this buffer has at least one underlying
ByteBuffer. Note that this method does not return 0 to avoid confusion.ByteBuf.nioBuffer(),
ByteBuf.nioBuffer(int, int),
ByteBuf.nioBuffers(),
ByteBuf.nioBuffers(int, int)public java.nio.ByteBuffer[] nioBuffers(int index,
int length)
ByteBufByteBuffer'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 modify readerIndex or writerIndex 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.public ByteBuf copy(int index, int length)
ByteBufreaderIndex or writerIndex of
this buffer.public java.nio.ByteBuffer internalNioBuffer(int index,
int length)
ByteBufinternalNioBuffer 在类中 ByteBufpublic java.nio.ByteBuffer nioBuffer(int index,
int length)
ByteBufByteBuffer. 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 modify readerIndex or writerIndex 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.protected void deallocate()
AbstractReferenceCountedByteBufAbstractReferenceCountedByteBuf.refCnt() is equals 0.public ByteBuf unwrap()
ByteBufprotected SwappedByteBuf newSwappedByteBuf()
AbstractByteBufSwappedByteBuf for this ByteBuf instance.newSwappedByteBuf 在类中 AbstractByteBufpublic ByteBuf setZero(int index, int length)
ByteBufindex.
This method does not modify readerIndex or writerIndex of
this buffer.setZero 在类中 AbstractByteBuflength - the number of NULs to write to the bufferpublic ByteBuf writeZero(int length)
ByteBufwriterIndex and increases the writerIndex by the
specified length.writeZero 在类中 AbstractByteBuflength - the number of NULs to write to the buffer