public class DefaultDataBuffer extends Object implements DataBuffer
DataBuffer interface that uses a ByteBuffer internally, with separate read and write positions. Constructed
using the DefaultDataBufferFactory.DefaultDataBufferFactory| 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) |
DefaultDataBufferFactory |
factory()
Return the
DataBufferFactory that created this buffer. |
ByteBuffer |
getNativeBuffer()
Directly exposes the native
ByteBuffer 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.
|
DefaultDataBuffer |
read(byte[] destination)
Read this buffer's data into the specified destination, starting at the current
reading position of this buffer.
|
DefaultDataBuffer |
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.
|
DataBuffer |
slice(int index,
int length)
Create a new
DataBuffer whose contents is a shared subsequence of this
data buffer's content. |
String |
toString() |
DefaultDataBuffer |
write(byte b)
Write a single byte into this buffer at the current writing position.
|
DefaultDataBuffer |
write(byte[] source)
Write the given source into this buffer, startin at the current writing position
of this buffer.
|
DefaultDataBuffer |
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. |
DefaultDataBuffer |
write(ByteBuffer... byteBuffers)
Write one or more
ByteBuffer to this buffer, starting at the current
writing position. |
DataBuffer |
write(DataBuffer... buffers)
Write one or more
DataBuffers to this buffer, starting at the current
writing position. |
public ByteBuffer getNativeBuffer()
ByteBuffer that this buffer is based on.public DefaultDataBufferFactory factory()
DataBufferDataBufferFactory that created this buffer.factory in interface DataBufferpublic int indexOf(IntPredicate predicate, int fromIndex)
DataBufferindexOf in interface DataBufferpredicate - the predicate to matchfromIndex - the index to start the search frompredicate; or -1
if none matchpublic int lastIndexOf(IntPredicate predicate, int fromIndex)
DataBufferlastIndexOf in interface DataBufferpredicate - the predicate to matchfromIndex - the index to start the search frompredicate; or -1
if none matchpublic int readableByteCount()
DataBufferreadableByteCount in interface DataBufferpublic byte read()
DataBufferread in interface DataBufferpublic DefaultDataBuffer read(byte[] destination)
DataBufferread in interface DataBufferdestination - the array into which the bytes are to be writtenpublic DefaultDataBuffer read(byte[] destination, int offset, int length)
DataBufferlength bytes of this buffer into the specified destination,
starting at the current reading position of this buffer.read in interface DataBufferdestination - 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 destinationpublic DefaultDataBuffer write(byte b)
DataBufferwrite in interface DataBufferb - the byte to be writtenpublic DefaultDataBuffer write(byte[] source)
DataBufferwrite in interface DataBuffersource - the bytes to be written into this bufferpublic DefaultDataBuffer write(byte[] source, int offset, int length)
DataBufferlength bytes of the given source into this buffer, starting
at the current writing position of this buffer.write in interface DataBuffersource - 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 sourcepublic DataBuffer write(DataBuffer... buffers)
DataBufferDataBuffers to this buffer, starting at the current
writing position.write in interface DataBufferbuffers - the byte buffers to write into this bufferpublic DefaultDataBuffer write(ByteBuffer... byteBuffers)
DataBufferByteBuffer to this buffer, starting at the current
writing position.write in interface DataBufferbyteBuffers - the byte buffers to write into this bufferpublic DataBuffer slice(int index, int length)
DataBufferDataBuffer 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 DataBufferindex - the index at which to start the slicelength - the length of the slicepublic ByteBuffer asByteBuffer()
DataBufferByteBuffer. 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 DataBufferpublic InputStream asInputStream()
DataBufferInputStream. Both data and position are
shared between the returned stream and this data buffer.asInputStream in interface DataBufferpublic OutputStream asOutputStream()
DataBufferOutputStream. Both data and position are
shared between the returned stream and this data buffer.asOutputStream in interface DataBuffer