A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands as necessary to accommodate any bytes written to it.
A Buffer represents a sequence of zero or more bytes that can be written to or read from, and which expands as necessary to accommodate any bytes written to it.
There are two ways to write data to a Buffer: The first method involves methods that take the form setXXX
.
These methods write data into the buffer starting at the specified position. The position does not have to be inside data that
has already been written to the buffer; the buffer will automatically expand to encompass the position plus any data that needs
to be written. All positions are measured in bytes and start with zero.
The second method involves methods that take the form appendXXX
; these methods append data
at the end of the buffer.
Methods exist to both set
and append
all primitive types, java.lang.String}, java.nio.ByteBuffer and
other instances of Buffer.
Data can be read from a buffer by invoking methods which take the form getXXX
. These methods take a parameter
representing the position in the Buffer from where to read data.
Once a buffer has been written to a socket or other write stream, the same buffer instance can't be written again to another WriteStream.
Instances of this class are not thread-safe.