public class CompositeReadableBuffer extends AbstractReadableBuffer
ReadableBuffer that is composed of 0 or more ReadableBuffers. This provides a
facade that allows multiple buffers to be treated as one.
When a buffer is added to a composite, its life cycle is controlled by the composite. Once the composite has read past the end of a given buffer, that buffer is automatically closed and removed from the composite.
| Constructor and Description |
|---|
CompositeReadableBuffer() |
| Modifier and Type | Method and Description |
|---|---|
void |
addBuffer(ReadableBuffer buffer)
Adds a new
ReadableBuffer at the end of the buffer list. |
void |
close()
Closes this buffer and releases any resources.
|
int |
readableBytes()
Gets the current number of readable bytes remaining in this buffer.
|
void |
readBytes(byte[] dest,
int destOffset,
int length)
Reads
length bytes from this buffer and writes them to the destination array. |
void |
readBytes(ByteBuffer dest)
Reads from this buffer until the destination's position reaches its limit, and increases the
read position by the number of the transferred bytes.
|
CompositeReadableBuffer |
readBytes(int length)
Reads
length bytes from this buffer and returns a new Buffer containing them. |
void |
readBytes(OutputStream dest,
int length)
Reads
length bytes from this buffer and writes them to the destination stream. |
int |
readUnsignedByte()
Reads the next unsigned byte from this buffer and increments the read position by 1.
|
void |
skipBytes(int length)
Increments the read position by the given length.
|
array, arrayOffset, checkReadable, hasArray, readIntpublic void addBuffer(ReadableBuffer buffer)
ReadableBuffer at the end of the buffer list. After a buffer is added, it is
expected that this CompositeBuffer has complete ownership. Any attempt to modify the
buffer (i.e. modifying the readable bytes) may result in corruption of the internal state of
this CompositeBuffer.public int readableBytes()
ReadableBufferpublic int readUnsignedByte()
ReadableBufferpublic void skipBytes(int length)
ReadableBufferpublic void readBytes(byte[] dest,
int destOffset,
int length)
ReadableBufferlength bytes from this buffer and writes them to the destination array.
Increments the read position by length.dest - the destination array to receive the bytes.destOffset - the starting offset in the destination array.length - the number of bytes to be copied.public void readBytes(ByteBuffer dest)
ReadableBufferdest - the destination buffer to receive the bytes.public void readBytes(OutputStream dest, int length) throws IOException
ReadableBufferlength bytes from this buffer and writes them to the destination stream.
Increments the read position by length. If the required bytes are not readable, throws
IndexOutOfBoundsException.dest - the destination stream to receive the bytes.length - the number of bytes to be copied.IOException - thrown if any error was encountered while writing to the stream.public CompositeReadableBuffer readBytes(int length)
ReadableBufferlength bytes from this buffer and returns a new Buffer containing them. Some
implementations may return a Buffer sharing the backing memory with this buffer to prevent
copying. However, that means that the returned buffer may keep the (possibly much larger)
backing memory in use even after this buffer is closed.length - the number of bytes to contain in returned Buffer.public void close()
ReadableBufferclose in interface ReadableBufferclose in interface Closeableclose in interface AutoCloseableclose in class AbstractReadableBuffer