DataBuffers has a separate read and
write position, as opposed to ByteBuffer's
single position. As such, the DataBuffer
does not require a flip to read after writing. In general,
the following invariant holds for the read and write positions, and the capacity:
0<=readPosition<=writePosition<=capacity
The capacity of a DataBuffer is expanded on demand,
similar to StringBuilder.
The main purpose of the DataBuffer abstraction is to provide a convenient wrapper
around ByteBuffer which is similar to Netty's io. but
can also be used on non-Netty platforms (i.e. Servlet containers).
DataBufferFactory
| Modifier and Type | Class and Description |
|---|---|
| public static interface | DataBuffer.
A dedicated iterator type that ensures the lifecycle of iterated
|
| Modifier and Type | Method and Description |
|---|---|
| public ByteBuffer | Returns: this data buffer as a byte buffer
Deprecated
since 6.0. as of 6.0, in favor of
toByteBuffer(ByteBuffer),
readableByteBuffers(), or writableByteBuffers().
Expose this buffer's bytes as a |
| public ByteBuffer | Returns: this data buffer as a byte bufferthe index at which to start the byte buffer index, int the length of the returned byte buffer length)
Deprecated
since 6.0. as of 6.0, in favor of
toByteBuffer(int, ByteBuffer, int, int),
readableByteBuffers(), or writableByteBuffers().
Expose a subsequence of this buffer's bytes as a |
| public default InputStream | Returns: this data buffer as an input streamExpose this buffer's data as an |
| public default InputStream | Returns: this data buffer as an input streamExpose this buffer's data as an |
| public default OutputStream | Returns: this data buffer as an output streamExpose this buffer's data as an |
| public int | |
| public DataBuffer | Returns: this bufferthe new capacity capacity)
Deprecated
since 6.0. as of 6.0, in favor of
ensureWritable(int), which
has different semantics
Set the number of bytes that this buffer can contain. |
| public default DataBuffer | Returns: this bufferthe writable capacity to check for capacity)
Deprecated
since 6.0. since 6.0, in favor of
ensureWritable(int)
Ensure that the current buffer has enough |
| public DataBuffer | Returns: this bufferthe writable capacity to check for capacity)Ensure that the current buffer has enough |
| public DataBufferFactory | |
| public byte | Returns: the byte at the given indexthe index at which the byte will be read index)Read a single byte at the given index from this data buffer. |
| public int | Returns: the index of the first byte that matchespredicate;
or -1 if none matchthe predicate to match predicate, int the index to start the search from fromIndex)Return the index of the first byte in this buffer that matches the given predicate. |
| public int | Returns: the index of the last byte that matchespredicate;
or -1 if none matchthe predicate to match predicate, int the index to start the search from fromIndex)Return the index of the last byte in this buffer that matches the given predicate. |
| public byte | Returns: the byte at this buffer's current reading positionRead a single byte from the current reading position from this data buffer. |
| public DataBuffer | Returns: this bufferthe array into which the bytes are to be written destination)Read this buffer's data into the specified destination, starting at the current reading position of this buffer. |
| public DataBuffer | Returns: this bufferthe array into which the bytes are to be written destination, int the index within offset, int destination of the first byte to be writtenthe maximum number of bytes to be written in length)destinationRead at most |
| public DataBuffer. | Returns: a closeable iterator over the readable byte buffers contained in this data bufferReturns a closeable iterator over each |
| public int | Returns: the readable byte countReturn the number of bytes that can be read from this data buffer. |
| public int | |
| public DataBuffer | Returns: this bufferthe new read position readPosition)Set the position from which this buffer will read. |
| public default DataBuffer | Returns: the specified, retained slice of this data bufferthe index at which to start the slice index, int the length of the slice length)
Deprecated
since 6.0. as of 6.0, in favor of
split(int), which
has different semantics
Create a new |
| public DataBuffer | Returns: the specified slice of this data bufferthe index at which to start the slice index, int the length of the slice length)
Deprecated
since 6.0. as of 6.0, in favor of
split(int), which
has different semantics
Create a new |
| public DataBuffer | Returns: a new data buffer, containing the bytes from index0 to
indexthe index at which it should be split index)Splits this data buffer into two at the given index. |
| public default ByteBuffer | Returns: this data buffer as a byte buffer
Deprecated
since 6.0.5. as of 6.0.5, in favor of
toByteBuffer(ByteBuffer)
Returns a |
| public ByteBuffer | Returns: this data buffer as a byte buffer
Deprecated
since 6.0.5. as of 6.0.5, in favor of
toByteBuffer(int, ByteBuffer, int, int)
Returns a |
| public default void | toByteBuffer(ByteBuffer
the destination byte buffer dest)Copies this entire data buffer into the given destination
|
| public void | toByteBuffer(int
the position of this data buffer from where copying should start srcPos, ByteBuffer the destination byte buffer dest, int the position in destPos, int dest to where copying should startthe amount of data to copy length)Copies the given length from this data buffer into the given destination
|
| public default String | |
| public String | |
| public DataBuffer. | Returns: a closeable iterator over the writable byte buffers contained in this data bufferReturns a closeable iterator over each |
| public int | Returns: the writable byte countReturn the number of bytes that can be written to this data buffer. |
| public DataBuffer | Returns: this bufferthe byte to be written b)Write a single byte into this buffer at the current writing position. |
| public DataBuffer | Returns: this bufferthe bytes to be written into this buffer source)Write the given source into this buffer, starting at the current writing position of this buffer. |
| public DataBuffer | Returns: this bufferthe bytes to be written into this buffer source, int the index within offset, int source to start writing fromthe maximum number of bytes to be written from length)sourceWrite at most |
| public DataBuffer | Returns: this bufferthe byte buffers to write into this buffer buffers)Write one or more |
| public DataBuffer | Returns: this bufferthe byte buffers to write into this buffer buffers)Write one or more |
| public default DataBuffer | Returns: this bufferthe char sequence to write into this buffer charSequence, Charset the charset to encode the char sequence with charset)Write the given |
| public int | |
| public DataBuffer | Returns: this bufferthe new write position writePosition)Set the position to which this buffer will write. |
| asByteBuffer | back to summary |
|---|---|
| public ByteBuffer asByteBuffer()
Deprecated since 6.0. as of 6.0, in favor of Expose this buffer's bytes as a
| |
| asByteBuffer | back to summary |
|---|---|
| public ByteBuffer asByteBuffer(int index, int length)
Deprecated since 6.0. as of 6.0, in favor of Expose a subsequence of this buffer's bytes as a
| |
| asInputStream | back to summary |
|---|---|
| public default InputStream asInputStream() Expose this buffer's data as an
| |
| asInputStream | back to summary |
|---|---|
| public default InputStream asInputStream(boolean releaseOnClose) Expose this buffer's data as an
| |
| asOutputStream | back to summary |
|---|---|
| public default OutputStream asOutputStream() Expose this buffer's data as an
| |
| capacity | back to summary |
|---|---|
| public int capacity() Return the number of bytes that this buffer can contain.
| |
| capacity | back to summary |
|---|---|
| public DataBuffer capacity(int capacity)
Set the number of bytes that this buffer can contain. If the new capacity is lower than the current capacity, the contents of this buffer will be truncated. If the new capacity is higher than the current capacity, it will be expanded.
| |
| ensureCapacity | back to summary |
|---|---|
| public default DataBuffer ensureCapacity(int capacity)
Ensure that the current buffer has enough
| |
| ensureWritable | back to summary |
|---|---|
| public DataBuffer ensureWritable(int capacity) Ensure that the current buffer has enough
| |
| factory | back to summary |
|---|---|
| public DataBufferFactory factory() Return the
| |
| getByte | back to summary |
|---|---|
| public byte getByte(int index) Read a single byte at the given index from this data buffer.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(IntPredicate predicate, int fromIndex) Return the index of the first byte in this buffer that matches the given predicate.
| |
| lastIndexOf | back to summary |
|---|---|
| public int lastIndexOf(IntPredicate predicate, int fromIndex) Return the index of the last byte in this buffer that matches the given predicate.
| |
| read | back to summary |
|---|---|
| public byte read() Read a single byte from the current reading position from this data buffer.
| |
| read | back to summary |
|---|---|
| public DataBuffer read(byte[] destination) Read this buffer's data into the specified destination, starting at the current reading position of this buffer.
| |
| read | back to summary |
|---|---|
| public DataBuffer read(byte[] destination, int offset, int length) Read at most
| |
| readableByteBuffers | back to summary |
|---|---|
| public DataBuffer. Returns a closeable iterator over each Note that the returned iterator must be used in a try-with-resources clause or explicitly closed.
| |
| readableByteCount | back to summary |
|---|---|
| public int readableByteCount() Return the number of bytes that can be read from this data buffer.
| |
| readPosition | back to summary |
|---|---|
| public int readPosition() Return the position from which this buffer will read.
| |
| readPosition | back to summary |
|---|---|
| public DataBuffer readPosition(int readPosition) Set the position from which this buffer will read.
| |
| retainedSlice | back to summary |
|---|---|
| public default DataBuffer retainedSlice(int index, int length)
Create a new Note that unlike
| |
| slice | back to summary |
|---|---|
| public DataBuffer slice(int index, int length)
Create a new Note that this method will not call
| |
| split | back to summary |
|---|---|
| public DataBuffer split(int index) Splits this data buffer into two at the given index. Data that precedes the The read and
write position of the returned buffer are
truncated to fit within the buffers capacity if
necessary. The positions of this buffer are set to
| |
| toByteBuffer | back to summary |
|---|---|
| public default ByteBuffer toByteBuffer()
Returns a
| |
| toByteBuffer | back to summary |
|---|---|
| public ByteBuffer toByteBuffer(int index, int length)
Returns a
| |
| toByteBuffer | back to summary |
|---|---|
| public default void toByteBuffer(ByteBuffer dest) Copies this entire data buffer into the given destination
| |
| toByteBuffer | back to summary |
|---|---|
| public void toByteBuffer(int srcPos, ByteBuffer dest, int destPos, int length) Copies the given length from this data buffer into the given destination
| |
| toString | back to summary |
|---|---|
| public default String toString(Charset charset) Return this buffer's data a String using the specified charset. Default implementation
delegates to | |
| toString | back to summary |
|---|---|
| public String toString(int index, int length, Charset charset) Return a part of this buffer's data as a String using the specified charset. | |
| writableByteBuffers | back to summary |
|---|---|
| public DataBuffer. Returns a closeable iterator over each Note that the returned iterator must be used in a try-with-resources clause or explicitly closed.
| |
| writableByteCount | back to summary |
|---|---|
| public int writableByteCount() Return the number of bytes that can be written to this data buffer.
| |
| write | back to summary |
|---|---|
| public DataBuffer write(byte b) Write a single byte into this buffer at the current writing position.
| |
| write | back to summary |
|---|---|
| public DataBuffer write(byte[] source) Write the given source into this buffer, starting at the current writing position of this buffer.
| |
| write | back to summary |
|---|---|
| public DataBuffer write(byte[] source, int offset, int length) Write at most
| |
| write | back to summary |
|---|---|
| public DataBuffer write(DataBuffer... buffers) Write one or more
| |
| write | back to summary |
|---|---|
| public DataBuffer write(ByteBuffer... buffers) Write one or more
| |
| write | back to summary |
|---|---|
| public default DataBuffer write(CharSequence charSequence, Charset charset) Write the given
| |
| writePosition | back to summary |
|---|---|
| public int writePosition() Return the position to which this buffer will write.
| |
| writePosition | back to summary |
|---|---|
| public DataBuffer writePosition(int writePosition) Set the position to which this buffer will write.
| |
ByteBuffer elements. This iterator must be used in a
try-with-resources clause or explicitly closed.
DataBuffer#readableByteBuffers(), DataBuffer#writableByteBuffers()
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Redeclares java. Closes this stream and releases any system resources associated with it. |
| close | back to summary |
|---|---|
| public void close() Redeclares java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in
| |