public class NioDataBuffer extends Object implements DataBuffer
ByteBuffer
. If the backing ByteBuffer is
a direct ByteBuffer, release()
should only be called when all references to the
object are finished with it. For this reason, it is not recommended to share objects of this
class unless reference counting is implemented by the users of this class.Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
mBuffer |
protected long |
mLength |
Constructor and Description |
---|
NioDataBuffer(ByteBuffer buffer,
long length) |
Modifier and Type | Method and Description |
---|---|
long |
getLength()
Returns the length of the data.
|
Object |
getNettyOutput()
Returns an object for writing to a netty channel.
|
ByteBuffer |
getReadOnlyByteBuffer()
Returns a
ByteBuffer for read-only access to the data. |
int |
readableBytes() |
void |
readBytes(byte[] dst,
int dstIndex,
int length)
Transfers this buffer's data to the specified destination starting at
the current
readerIndex and increases the readerIndex
by the number of the transferred bytes (= length ). |
void |
readBytes(ByteBuffer outputBuf)
Transfers this buffer's data to the given
ByteBuffer . |
void |
readBytes(OutputStream outputStream,
int length)
Transfers this buffer's data to the given stream.
|
void |
release()
Releases the underlying buffer of this DataBuffer if no longer needed.
|
protected final ByteBuffer mBuffer
protected final long mLength
public NioDataBuffer(ByteBuffer buffer, long length)
buffer
- The ByteBuffer representing the datalength
- The length of the ByteBufferpublic Object getNettyOutput()
DataBuffer
getNettyOutput
in interface DataBuffer
public long getLength()
DataBuffer
getLength
in interface DataBuffer
public ByteBuffer getReadOnlyByteBuffer()
DataBuffer
ByteBuffer
for read-only access to the data.getReadOnlyByteBuffer
in interface DataBuffer
public void readBytes(byte[] dst, int dstIndex, int length)
DataBuffer
readerIndex
and increases the readerIndex
by the number of the transferred bytes (= length
).readBytes
in interface DataBuffer
dst
- the destinationdstIndex
- the first index of the destinationlength
- the number of bytes to transferpublic void readBytes(OutputStream outputStream, int length) throws IOException
DataBuffer
readBytes
in interface DataBuffer
outputStream
- the stream to transfer data tolength
- length of the data to be transferredIOException
public void readBytes(ByteBuffer outputBuf)
DataBuffer
ByteBuffer
.readBytes
in interface DataBuffer
outputBuf
- the buffer to transfer data topublic int readableBytes()
readableBytes
in interface DataBuffer
public void release()
DataBuffer
release
in interface DataBuffer
Copyright © 2023. All Rights Reserved.