public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf
Modifier | Constructor and Description |
---|---|
protected |
UnpooledHeapByteBuf(ByteBufAllocator alloc,
byte[] initialArray,
int maxCapacity)
Creates a new heap buffer with an existing byte array.
|
protected |
UnpooledHeapByteBuf(ByteBufAllocator alloc,
int initialCapacity,
int maxCapacity)
Creates a new heap buffer with a newly allocated byte array.
|
Modifier and Type | Method and Description |
---|---|
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. |
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. |
byte |
getByte(int index)
Gets a byte at the specified absolute
index in this buffer. |
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,
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,
GatheringByteChannel out,
int length)
Transfers this buffer's data to the specified channel starting at the
specified absolute
index . |
ByteBuf |
getBytes(int index,
OutputStream out,
int length)
Transfers this buffer's data to the specified stream starting at the
specified absolute
index . |
int |
getInt(int index)
Gets a 32-bit integer at the specified absolute
index in
this buffer. |
long |
getLong(int index)
Gets a 64-bit long integer at the specified absolute
index in
this buffer. |
short |
getShort(int index)
Gets a 16-bit short integer at the specified absolute
index in
this buffer. |
int |
getUnsignedMedium(int index)
Gets an unsigned 24-bit medium integer at the specified absolute
index in this buffer. |
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. |
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.
|
ByteBuffer |
nioBuffer(int index,
int length)
Exposes this buffer's sub-region as an NIO
ByteBuffer . |
int |
nioBufferCount()
Returns the maximum number of NIO
ByteBuffer s that consist this buffer. |
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 shares the content with this buffer, while changing the position and limit
of the returned NIO buffer does not affect the indexes and marks of this buffer. |
ByteOrder |
order()
Returns the endianness
of this buffer.
|
int |
readBytes(GatheringByteChannel out,
int length)
Transfers this buffer's data to the specified stream starting at the
current
readerIndex . |
ByteBuf |
setByte(int index,
int value)
Sets the specified byte at the specified absolute
index 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 absolute
index . |
ByteBuf |
setBytes(int index,
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,
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,
ScatteringByteChannel in,
int length)
Transfers the content of the specified source channel to this buffer
starting at the specified absolute
index . |
ByteBuf |
setInt(int index,
int value)
Sets the specified 32-bit integer at the specified absolute
index in this buffer. |
ByteBuf |
setLong(int index,
long value)
Sets the specified 64-bit long integer at the specified absolute
index in this buffer. |
ByteBuf |
setMedium(int index,
int value)
Sets the specified 24-bit medium integer at the specified absolute
index in this buffer. |
ByteBuf |
setShort(int index,
int value)
Sets the specified 16-bit short integer at the specified absolute
index in this buffer. |
ByteBuf |
unwrap()
Return the underlying buffer instance if this buffer is a wrapper of another buffer.
|
refCnt, release, release, retain, retain, setRefCnt, touch, touch
adjustMarkers, bytesBefore, bytesBefore, bytesBefore, checkDstIndex, checkIndex, checkIndex, checkReadableBytes, checkSrcIndex, clear, compareTo, copy, discardReadBytes, discardSomeReadBytes, duplicate, ensureAccessible, ensureWritable, ensureWritable, equals, forEachByte, forEachByte, forEachByteDesc, forEachByteDesc, getBoolean, getBytes, getBytes, getBytes, getChar, getDouble, getFloat, getMedium, getUnsignedByte, getUnsignedInt, getUnsignedShort, hashCode, indexOf, isReadable, isReadable, isWritable, isWritable, markReaderIndex, markWriterIndex, maxCapacity, maxCapacity, maxWritableBytes, newSwappedByteBuf, nioBuffer, nioBuffers, order, readableBytes, readBoolean, readByte, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readChar, readDouble, readerIndex, readerIndex, readFloat, readInt, readLong, readMedium, readShort, readSlice, readUnsignedByte, readUnsignedInt, readUnsignedMedium, readUnsignedShort, resetReaderIndex, resetWriterIndex, setBoolean, setBytes, setBytes, setBytes, setChar, setDouble, setFloat, setIndex, setZero, 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, writeShort, writeZero
protected UnpooledHeapByteBuf(ByteBufAllocator alloc, int initialCapacity, int maxCapacity)
initialCapacity
- the initial capacity of the underlying byte arraymaxCapacity
- the max capacity of the underlying byte arrayprotected UnpooledHeapByteBuf(ByteBufAllocator alloc, byte[] initialArray, int maxCapacity)
initialArray
- the initial underlying byte arraymaxCapacity
- the max capacity of the underlying byte arraypublic ByteBufAllocator alloc()
ByteBuf
ByteBufAllocator
which created this buffer.public ByteOrder order()
ByteBuf
public boolean isDirect()
ByteBuf
true
if and only if this buffer is backed by an
NIO direct buffer.public int capacity()
ByteBuf
public ByteBuf capacity(int newCapacity)
ByteBuf
newCapacity
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 boolean hasArray()
ByteBuf
true
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()
ByteBuf
public int arrayOffset()
ByteBuf
arrayOffset
in class ByteBuf
public boolean hasMemoryAddress()
ByteBuf
true
if and only if this buffer has a reference to the low-level memory address that points
to the backing data.hasMemoryAddress
in class ByteBuf
public long memoryAddress()
ByteBuf
memoryAddress
in class ByteBuf
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length)
ByteBuf
index
.
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)
ByteBuf
index
.
This method does not modify readerIndex
or writerIndex
of this buffer.public ByteBuf getBytes(int index, ByteBuffer dst)
ByteBuf
index
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 getBytes(int index, OutputStream out, int length) throws IOException
ByteBuf
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.getBytes
in class ByteBuf
length
- the number of bytes to transferIOException
- if the specified stream threw an exception during I/Opublic int getBytes(int index, GatheringByteChannel out, int length) throws IOException
ByteBuf
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.getBytes
in class ByteBuf
length
- the maximum number of bytes to transferIOException
- if the specified channel threw an exception during I/Opublic int readBytes(GatheringByteChannel out, int length) throws IOException
ByteBuf
readerIndex
.readBytes
in class AbstractByteBuf
length
- the maximum number of bytes to transferIOException
- if the specified channel threw an exception during I/Opublic ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length)
ByteBuf
index
.
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)
ByteBuf
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.public ByteBuf setBytes(int index, ByteBuffer src)
ByteBuf
index
until the source buffer's position
reaches its limit.
This method does not modify readerIndex
or writerIndex
of
this buffer.public int setBytes(int index, InputStream in, int length) throws IOException
ByteBuf
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.setBytes
in class ByteBuf
length
- the number of bytes to transfer-1
if the specified channel is closed.IOException
- if the specified stream threw an exception during I/Opublic int setBytes(int index, ScatteringByteChannel in, int length) throws IOException
ByteBuf
index
.
This method does not modify readerIndex
or writerIndex
of
this buffer.setBytes
in class ByteBuf
length
- the maximum number of bytes to transfer-1
if the specified channel is closed.IOException
- if the specified channel threw an exception during I/Opublic int nioBufferCount()
ByteBuf
ByteBuffer
s that consist this buffer. Note that ByteBuf.nioBuffers()
or ByteBuf.nioBuffers(int, int)
might return a less number of ByteBuffer
s.nioBufferCount
in class ByteBuf
-1
if this buffer has no underlying ByteBuffer
.
the number of the underlying ByteBuffer
s 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 ByteBuffer nioBuffer(int index, int length)
ByteBuf
ByteBuffer
. The returned buffer
shares the content with 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.nioBuffer
in class ByteBuf
ByteBuf.nioBufferCount()
,
ByteBuf.nioBuffers()
,
ByteBuf.nioBuffers(int, int)
public ByteBuffer[] nioBuffers(int index, int length)
ByteBuf
ByteBuffer
's for the specified index and length
The returned buffer shares the content with 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.nioBuffers
in class ByteBuf
ByteBuf.nioBufferCount()
,
ByteBuf.nioBuffer()
,
ByteBuf.nioBuffer(int, int)
public ByteBuffer internalNioBuffer(int index, int length)
ByteBuf
internalNioBuffer
in class ByteBuf
public byte getByte(int index)
ByteBuf
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.getByte
in class AbstractByteBuf
protected byte _getByte(int index)
_getByte
in class AbstractByteBuf
public short getShort(int index)
ByteBuf
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.getShort
in class AbstractByteBuf
protected short _getShort(int index)
_getShort
in class AbstractByteBuf
public int getUnsignedMedium(int index)
ByteBuf
index
in this buffer. This method does not modify
readerIndex
or writerIndex
of this buffer.getUnsignedMedium
in class AbstractByteBuf
protected int _getUnsignedMedium(int index)
_getUnsignedMedium
in class AbstractByteBuf
public int getInt(int index)
ByteBuf
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.getInt
in class AbstractByteBuf
protected int _getInt(int index)
_getInt
in class AbstractByteBuf
public long getLong(int index)
ByteBuf
index
in
this buffer. This method does not modify readerIndex
or
writerIndex
of this buffer.getLong
in class AbstractByteBuf
protected long _getLong(int index)
_getLong
in class AbstractByteBuf
public ByteBuf setByte(int index, int value)
ByteBuf
index
in this
buffer. The 24 high-order bits of the specified value are ignored.
This method does not modify readerIndex
or writerIndex
of
this buffer.setByte
in class AbstractByteBuf
protected void _setByte(int index, int value)
_setByte
in class AbstractByteBuf
public ByteBuf setShort(int index, int value)
ByteBuf
index
in this buffer. The 16 high-order bits of the specified
value are ignored.
This method does not modify readerIndex
or writerIndex
of
this buffer.setShort
in class AbstractByteBuf
protected void _setShort(int index, int value)
_setShort
in class AbstractByteBuf
public ByteBuf setMedium(int index, int value)
ByteBuf
index
in this buffer. Please note that the most significant
byte is ignored in the specified value.
This method does not modify readerIndex
or writerIndex
of
this buffer.setMedium
in class AbstractByteBuf
protected void _setMedium(int index, int value)
_setMedium
in class AbstractByteBuf
public ByteBuf setInt(int index, int value)
ByteBuf
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.setInt
in class AbstractByteBuf
protected void _setInt(int index, int value)
_setInt
in class AbstractByteBuf
public ByteBuf setLong(int index, long value)
ByteBuf
index
in this buffer.
This method does not modify readerIndex
or writerIndex
of
this buffer.setLong
in class AbstractByteBuf
protected void _setLong(int index, long value)
_setLong
in class AbstractByteBuf
public ByteBuf copy(int index, int length)
ByteBuf
readerIndex
or writerIndex
of
this buffer.protected void deallocate()
AbstractReferenceCountedByteBuf
AbstractReferenceCountedByteBuf.refCnt()
is equals 0.deallocate
in class AbstractReferenceCountedByteBuf
Copyright © 2008–2015 The Netty Project. All rights reserved.