public interface ReadableBuffer extends Closeable
Buffers may optionally expose a backing array for optimization purposes, similar to what is
done in ByteBuffer
. It is not expected that callers will attempt to modify the backing
array.
Modifier and Type | Method and Description |
---|---|
byte[] |
array()
Gets the backing array for this buffer.
|
int |
arrayOffset()
Gets the offset in the backing array of the current read position.
|
void |
close()
Closes this buffer and releases any resources.
|
boolean |
hasArray()
Indicates whether or not this buffer exposes a backing array.
|
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.
|
ReadableBuffer |
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 |
readInt()
Reads a 4-byte signed integer from this buffer using big-endian byte ordering.
|
int |
readUnsignedByte()
Reads the next unsigned byte from this buffer and increments the read position by 1.
|
int |
readUnsignedMedium()
Reads a 3-byte unsigned integer from this buffer using big-endian byte ordering.
|
int |
readUnsignedShort()
Reads a 2-byte unsigned integer from this buffer using big-endian byte ordering.
|
void |
skipBytes(int length)
Increments the read position by the given length.
|
int readableBytes()
int readUnsignedByte()
IndexOutOfBoundsException
- if required bytes are not readableint readUnsignedMedium()
IndexOutOfBoundsException
- if required bytes are not readableint readUnsignedShort()
IndexOutOfBoundsException
- if required bytes are not readableint readInt()
IndexOutOfBoundsException
- if required bytes are not readablevoid skipBytes(int length)
IndexOutOfBoundsException
- if required bytes are not readablevoid readBytes(byte[] dest, int destOffset, int length)
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.IndexOutOfBoundsException
- if required bytes are not readable or dest
is too
small.void readBytes(ByteBuffer dest)
dest
- the destination buffer to receive the bytes.IndexOutOfBoundsException
- if required bytes are not readablevoid readBytes(OutputStream dest, int length) throws IOException
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.IndexOutOfBoundsException
- if required bytes are not readableReadableBuffer readBytes(int length)
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.IndexOutOfBoundsException
- if required bytes are not readableboolean hasArray()
byte[] array()
hasArray()
.UnsupportedOperationException
- the buffer does not support this methodint arrayOffset()
hasArray()
UnsupportedOperationException
- the buffer does not support this methodvoid close()
close
in interface AutoCloseable
close
in interface Closeable