public class NettyDataBuffer extends Object implements PooledDataBuffer
DataBuffer
interface that wraps a Netty
ByteBuf
. Typically constructed with NettyDataBufferFactory
.Modifier and Type | Method and Description |
---|---|
ByteBuffer |
asByteBuffer()
Expose this buffer's bytes as a
ByteBuffer . |
InputStream |
asInputStream()
Expose this buffer's data as an
InputStream . |
OutputStream |
asOutputStream()
Expose this buffer's data as an
OutputStream . |
boolean |
equals(Object obj) |
NettyDataBufferFactory |
factory()
Return the
DataBufferFactory that created this buffer. |
io.netty.buffer.ByteBuf |
getNativeBuffer()
Directly exposes the native
ByteBuf that this buffer is based on. |
int |
hashCode() |
int |
indexOf(IntPredicate predicate,
int fromIndex)
Return the index of the first byte in this buffer that matches the given
predicate.
|
int |
lastIndexOf(IntPredicate predicate,
int fromIndex)
Return the index of the last byte in this buffer that matches the given
predicate.
|
byte |
read()
Read a single byte from the current reading position of this data buffer.
|
NettyDataBuffer |
read(byte[] destination)
Read this buffer's data into the specified destination, starting at the current
reading position of this buffer.
|
NettyDataBuffer |
read(byte[] destination,
int offset,
int length)
Read at most
length bytes of this buffer into the specified destination,
starting at the current reading position of this buffer. |
int |
readableByteCount()
Return the number of bytes that can be read from this data buffer.
|
boolean |
release()
Decrease the reference count for this buffer by one, and release it
once the count reaches zero.
|
PooledDataBuffer |
retain()
Increase the reference count for this buffer by one.
|
DataBuffer |
slice(int index,
int length)
Create a new
DataBuffer whose contents is a shared subsequence of this
data buffer's content. |
String |
toString() |
NettyDataBuffer |
write(byte b)
Write a single byte into this buffer at the current writing position.
|
NettyDataBuffer |
write(byte[] source)
Write the given source into this buffer, startin at the current writing position
of this buffer.
|
NettyDataBuffer |
write(byte[] source,
int offset,
int length)
Write at most
length bytes of the given source into this buffer, starting
at the current writing position of this buffer. |
NettyDataBuffer |
write(io.netty.buffer.ByteBuf... byteBufs)
Writes one or more Netty
ByteBuf s to this buffer, starting at the current
writing position. |
NettyDataBuffer |
write(ByteBuffer... buffers)
Write one or more
ByteBuffer to this buffer, starting at the current
writing position. |
NettyDataBuffer |
write(DataBuffer... buffers)
Write one or more
DataBuffer s to this buffer, starting at the current
writing position. |
public io.netty.buffer.ByteBuf getNativeBuffer()
ByteBuf
that this buffer is based on.public NettyDataBufferFactory factory()
DataBuffer
DataBufferFactory
that created this buffer.factory
in interface DataBuffer
public int indexOf(IntPredicate predicate, int fromIndex)
DataBuffer
indexOf
in interface DataBuffer
predicate
- the predicate to matchfromIndex
- the index to start the search frompredicate
; or -1
if none matchpublic int lastIndexOf(IntPredicate predicate, int fromIndex)
DataBuffer
lastIndexOf
in interface DataBuffer
predicate
- the predicate to matchfromIndex
- the index to start the search frompredicate
; or -1
if none matchpublic int readableByteCount()
DataBuffer
readableByteCount
in interface DataBuffer
public byte read()
DataBuffer
read
in interface DataBuffer
public NettyDataBuffer read(byte[] destination)
DataBuffer
read
in interface DataBuffer
destination
- the array into which the bytes are to be writtenpublic NettyDataBuffer read(byte[] destination, int offset, int length)
DataBuffer
length
bytes of this buffer into the specified destination,
starting at the current reading position of this buffer.read
in interface DataBuffer
destination
- the array into which the bytes are to be writtenoffset
- the index within destination
of the first byte to be writtenlength
- the maximum number of bytes to be written in destination
public NettyDataBuffer write(byte b)
DataBuffer
write
in interface DataBuffer
b
- the byte to be writtenpublic NettyDataBuffer write(byte[] source)
DataBuffer
write
in interface DataBuffer
source
- the bytes to be written into this bufferpublic NettyDataBuffer write(byte[] source, int offset, int length)
DataBuffer
length
bytes of the given source into this buffer, starting
at the current writing position of this buffer.write
in interface DataBuffer
source
- the bytes to be written into this bufferoffset
- the index withing source
to start writing fromlength
- the maximum number of bytes to be written from source
public NettyDataBuffer write(DataBuffer... buffers)
DataBuffer
DataBuffer
s to this buffer, starting at the current
writing position.write
in interface DataBuffer
buffers
- the byte buffers to write into this bufferpublic NettyDataBuffer write(ByteBuffer... buffers)
DataBuffer
ByteBuffer
to this buffer, starting at the current
writing position.write
in interface DataBuffer
buffers
- the byte buffers to write into this bufferpublic NettyDataBuffer write(io.netty.buffer.ByteBuf... byteBufs)
ByteBuf
s to this buffer, starting at the current
writing position.byteBufs
- the buffers to write into this bufferpublic DataBuffer slice(int index, int length)
DataBuffer
DataBuffer
whose contents is a shared subsequence of this
data buffer's content. Data between this data buffer and the returned buffer is
shared; though changes in the returned buffer's position will not be reflected
in the reading nor writing position of this data buffer.slice
in interface DataBuffer
index
- the index at which to start the slicelength
- the length of the slicepublic ByteBuffer asByteBuffer()
DataBuffer
ByteBuffer
. Data between this
DataBuffer
and the returned ByteBuffer
is shared; though
changes in the returned buffer's position
will not be reflected in the reading nor writing position of this data buffer.asByteBuffer
in interface DataBuffer
public InputStream asInputStream()
DataBuffer
InputStream
. Both data and position are
shared between the returned stream and this data buffer.asInputStream
in interface DataBuffer
public OutputStream asOutputStream()
DataBuffer
OutputStream
. Both data and position are
shared between the returned stream and this data buffer.asOutputStream
in interface DataBuffer
public PooledDataBuffer retain()
PooledDataBuffer
retain
in interface PooledDataBuffer
public boolean release()
PooledDataBuffer
release
in interface PooledDataBuffer
true
if the buffer was released; false
otherwise.