img
Buffers
Buffers are defined in the java.nio package. All buffers are subclasses of the Buffer class,
which defines the core functionality common to all buffers: current position, limit, and
capacity. The current position is the index within the buffer at which the next read or write
operation will take place. The current position is advanced by most read or write operations.
The limit is the index of the end of the buffer. The capacity is the number of elements that
the buffer can hold. Buffer also supports mark and reset. Buffer defines several methods,
which are shown in Table 27-2.
Method
Description
abstract Object array( )
If the invoking buffer is backed by an array, a reference to the array
is returned. Other wise, an UnsupportedOperationException is
thrown. If the array is read-only, a ReadOnlyBufferException is
thrown. (Added by Java SE 6.)
abstract int arrayOf fset( )
If the invoking buffer is backed by an array, the index
of the first element is returned. Other wise, an
UnsupportedOperationException is thrown. If the array is read-only,
a ReadOnlyBufferException is thrown. (Added by Java SE 6.)
final int capacity( )
Returns the number of elements that the invoking buf fer
is capable of holding.
final Buf fer clear( )
Clears the invoking buf fer and returns a reference to the buf fer.
final Buf fer flip( )
Sets the invoking buf fer's limit to the current position and resets
the current position to 0. Returns a reference to the buf fer.
abstract boolean hasArray( )
Returns true if the invoking buf fer is backed by a read/write
array and false other wise. (Added by Java SE 6.)
final boolean hasRemaining( )
Returns true if there are elements remaining in the invoking
buf fer. Returns false other wise.
abstract isDirect( )
Returns true if the invoking buf fer is direct, which means that it
can often be operated upon directly, rather than through a copy.
Returns false other wise. (Added by Java SE 6.)
abstract boolean isReadOnly( ) Returns true if the invoking buf fer is read-only. Returns false
other wise.
final int limit( )
Returns the invoking buf fer's limit.
final Buf fer limit(int n)
Sets the invoking buf fer's limit to n. Returns a reference
to the buf fer.
final Buf fer mark( )
Sets the mark and returns a reference to the invoking buf fer.
final int position( )
Returns the current position.
final Buf fer position(int n)
Sets the invoking buf fer's current position to n. Returns
a reference to the buf fer.
final Buf fer reset( )
Resets the current position of the invoking buffer to the previously
set mark. Returns a reference to the buffer.
final Buf fer rewind( )
Sets the position of the invoking buf fer to 0. Returns a reference
to the buf fer.
TABLE 27-2
The Methods Defined by Buffer
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home