public abstract class Buffer extends Object
A buffer can be described by the following properties:
limit - 1. Accessing
elements out of the scope will cause an exception. Limit may not be negative
and not greater than capacity.ReadOnlyBufferException,
while changing the position, limit and mark of a read-only buffer is OK.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.
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
Returns the capacity of this buffer.
|
Buffer |
clear()
Clears this buffer.
|
Buffer |
flip()
Flips this buffer.
|
boolean |
hasRemaining()
Indicates if there are elements remaining in this buffer, that is if
position < limit. |
abstract boolean |
isReadOnly()
Indicates whether this buffer is read-only.
|
int |
limit()
Returns the limit of this buffer.
|
Buffer |
limit(int newLimit)
Sets the limit of this buffer.
|
Buffer |
mark()
Marks the current position, so that the position may return to this point
later by calling
reset(). |
int |
position()
Returns the position of this buffer.
|
Buffer |
position(int newPosition)
Sets the position of this buffer.
|
int |
remaining()
Returns the number of remaining elements in this buffer, that is
limit - position. |
Buffer |
reset()
Resets the position of this buffer to the
mark. |
Buffer |
rewind()
Rewinds this buffer.
|
public final int capacity()
public final Buffer clear()
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 cleared.
public final Buffer flip()
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.
public final boolean hasRemaining()
position < limit.true if there are elements remaining in this buffer,
false otherwise.public abstract boolean isReadOnly()
true if this buffer is read-only, false
otherwise.public final int limit()
public final Buffer limit(int newLimit)
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.
newLimit - the new limit, must not be negative and not greater than
capacity.IllegalArgumentException - if newLimit is invalid.public final Buffer mark()
reset().public final int position()
public final Buffer position(int newPosition)
If the mark is set and it is greater than the new position, then it is cleared.
newPosition - the new position, must be not negative and not greater than
limit.IllegalArgumentException - if newPosition is invalid.public final int remaining()
limit - position.public final Buffer reset()
mark.InvalidMarkException - if the mark is not set.public final Buffer rewind()
The position is set to zero, and the mark is cleared. The content of this buffer is not changed.
Copyright © 2020 Dmitrii Tikhomirov. All rights reserved.