public class CompositeReadableBuffer extends AbstractReadableBuffer
ReadableBuffer
that is composed of 0 or more ReadableBuffer
s. 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, readInt, readUnsignedMedium, readUnsignedShort
public 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()
ReadableBuffer
public int readUnsignedByte()
ReadableBuffer
public void skipBytes(int length)
ReadableBuffer
public void readBytes(byte[] dest, int destOffset, int length)
ReadableBuffer
length
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)
ReadableBuffer
dest
- the destination buffer to receive the bytes.public void readBytes(OutputStream dest, int length) throws IOException
ReadableBuffer
length
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)
ReadableBuffer
length
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()
ReadableBuffer
close
in interface ReadableBuffer
close
in interface Closeable
close
in interface AutoCloseable
close
in class AbstractReadableBuffer