Name
Buffer
Synopsis
This class is the abstract superclass of
all buffer classes in the java.nio API. A
buffer is a linear (finite) sequence of
prmitive values. The java.nio package defines a
Buffer subclass for each
primitive type in Java except for
boolean. Buffer itself defines
the common, type-independent features of all buffers.
Buffer and its subclasses are intended for use by
a single thread at a time, and contain no synchronization code to
make them thread-safe.
The purpose of a buffer is to store data, and buffer classes must
define methods for reading data from a buffer and writing data into a
buffer. Because each Buffer subclass stores data
of a different primitive type, however, the get(
)
and
put( ) methods that read and write data must be
defined by each of the individual subclasses. See
ByteBuffer (the most important subclass) for
documentation of these methods; all the other subclasses define
similar methods which differ only in the datatype of the values being
read or written.
Each buffer has four numbers associated with it:
- capacity
A buffer’s capacity is its maximum size; it can hold this many values. The capacity is specified when a buffer is created, and may not be changed; it can be queried with the
capacity( )method.- limit
A buffer’s limit is its current size, or the index of the first element that does not contain valid data. Data cannot be read from or written into a buffer beyond the limit. When data is being written into a buffer, the limit is usually the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access