| java.lang.Object java.nio.Buffer
All known Subclasses: java.nio.LongBuffer, java.nio.FloatBuffer, java.nio.IntBuffer, java.nio.CharBuffer, java.nio.DoubleBuffer, java.nio.ByteBuffer, java.nio.ShortBuffer,
Buffer | abstract public class Buffer (Code) | | A buffer is a list of elements of a specific primitive type.
A buffer can be described by following properties:
- Capacity, is the number of elements a buffer can hold. Capacity is no
less than zero and never changes.
- Position, is a cursor of this buffer. Elements are read or write at the
position if you do not specify an index explicitly. Position is no less than
zero and no greater than the limit.
- Limit controls the scope of accessible elements. You can only read or
write elements from index zero to
limit - 1 . Accessing
elements out of the scope will cause exception. Limit is no less than zero
and no greater than capacity.
- Mark, is used to remember the current position, so that you can reset
the position later. Mark is no less than zero and no greater than position.
- A buffer can be readonly or read-write. Trying to modify the elements of
a readonly buffer will cause
ReadOnlyBufferException , while
changing the position, limit and mark of a readonly buffer is OK.
- A buffer can be direct or indirect. A direct buffer will try its best to
take advantage of native memory APIs and it may not stay in java heap, thus
not affected by GC.
Buffers are not thread-safe. If concurrent access to a buffer instance is
required, then the callers are responsible to take care of the
synchronization issues.
|
Field Summary | |
final static int | UNSET_MARK UNSET_MARK means the mark has not been set. | final int | capacity The capacity of this buffer, which never change. | int | limit limit - 1 is the last element that can be read or write. | int | mark Mark is the position will be set when reset() is called.
Mark is not set by default. | int | position The current position of this buffer. |
Constructor Summary | |
| Buffer(int capacity) Construct a buffer with the specified capacity. |
Method Summary | |
final public int | capacity() Returns the capacity of this buffer. | final public Buffer | clear() Clears this buffer. | final public Buffer | flip() Flips this buffer. | final public boolean | hasRemaining() Returns true if there are remaining element(s) in this buffer. | abstract public boolean | isReadOnly() Returns whether this buffer is readonly or not. | final public int | limit() Returns the limit of this buffer. | final public Buffer | limit(int newLimit) Sets the limit of this buffer.
If the current position in the buffer is in excess of
newLimit then, on returning from this call, it will have
been adjusted to be equivalent to newLimit . | final public Buffer | mark() Mark the current position, so that the position may return to this point
later by calling reset() . | final public int | position() Returns the position of this buffer. | final public Buffer | position(int newPosition) Sets the position of this buffer. | final public int | remaining() Returns the number of remaining elements in this buffer. | final public Buffer | reset() Reset the position of this buffer to the mark . | final public Buffer | rewind() Rewinds this buffer. |
UNSET_MARK | final static int UNSET_MARK(Code) | | UNSET_MARK means the mark has not been set.
|
capacity | final int capacity(Code) | | The capacity of this buffer, which never change.
|
limit | int limit(Code) | | limit - 1 is the last element that can be read or write.
Limit must be no less than zero and no greater than capacity .
|
mark | int mark(Code) | | Mark is the position will be set when reset() is called.
Mark is not set by default. Mark is always no less than zero and no
greater than position .
|
position | int position(Code) | | The current position of this buffer. Position is always no less than zero
and no greater than limit .
|
Buffer | Buffer(int capacity)(Code) | | Construct a buffer with the specified capacity.
Parameters: capacity - The capacity of this buffer |
capacity | final public int capacity()(Code) | | Returns the capacity of this buffer.
The number of elements that are contained in this buffer. |
clear | final public Buffer clear()(Code) | | Clears this buffer.
While the content of this buffer is not changed the following internal
changes take place : the current position is reset back to the start of
the buffer, the value of the buffer limit is made equal to the capacity
and mark is unset.
This buffer |
flip | final public Buffer flip()(Code) | | Flips this buffer.
The limit is set to the current position, then the position is set to
zero, and the mark is cleared.
The content of this buffer is not changed.
This buffer |
hasRemaining | final public boolean hasRemaining()(Code) | | Returns true if there are remaining element(s) in this buffer.
Or more precisely, returns position < limit .
True if there are remaining element(s) in this buffer. |
isReadOnly | abstract public boolean isReadOnly()(Code) | | Returns whether this buffer is readonly or not.
Whether this buffer is readonly or not. |
limit | final public int limit()(Code) | | Returns the limit of this buffer.
The limit of this buffer. |
limit | final public Buffer limit(int newLimit)(Code) | | Sets the limit of this buffer.
If the current position in the buffer is in excess of
newLimit then, on returning from this call, it will have
been adjusted to be equivalent to newLimit . If the mark
is set and is greater than the new limit, then it is cleared.
Parameters: newLimit - The new limit, must be no less than zero and no greater thancapacity This buffer exception: IllegalArgumentException - If newLimit is invalid. |
mark | final public Buffer mark()(Code) | | Mark the current position, so that the position may return to this point
later by calling reset() .
This buffer |
position | final public int position()(Code) | | Returns the position of this buffer.
The value of this buffer's current position. |
position | final public Buffer position(int newPosition)(Code) | | Sets the position of this buffer.
If the mark is set and is greater than the new position, then it is
cleared.
Parameters: newPosition - The new position, must be no less than zero and no greaterthan limit This buffer exception: IllegalArgumentException - If newPosition is invalid |
remaining | final public int remaining()(Code) | | Returns the number of remaining elements in this buffer.
Or more precisely, returns limit - position .
The number of remaining elements in this buffer. |
rewind | final public Buffer rewind()(Code) | | Rewinds this buffer.
The position is set to zero, and the mark is cleared.
The content of this buffer is not changed.
This buffer |
|
|