java.lang.Object | |
↳ | java.nio.Buffer |
Known Direct Subclasses |
Known Indirect Subclasses |
A buffer is a list of elements of a specific primitive type.
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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the array that backs this buffer (optional operation).
| |||||||||||
Returns the offset into the array returned by
array of the first
element of the buffer (optional operation). | |||||||||||
Returns the capacity of this buffer.
| |||||||||||
Clears this buffer.
| |||||||||||
Flips this buffer.
| |||||||||||
Returns true if
array and arrayOffset won't throw. | |||||||||||
Indicates if there are elements remaining in this buffer, that is if
position < limit . | |||||||||||
Returns true if this is a direct buffer.
| |||||||||||
Indicates whether this buffer is read-only.
| |||||||||||
Returns the limit of this buffer.
| |||||||||||
Sets the limit of this buffer.
| |||||||||||
Marks the current position, so that the position may return to this point
later by calling
reset() . | |||||||||||
Sets the position of this buffer.
| |||||||||||
Returns the position of this buffer.
| |||||||||||
Returns the number of remaining elements in this buffer, that is
limit - position . | |||||||||||
Resets the position of this buffer to the
mark . | |||||||||||
Rewinds this buffer.
| |||||||||||
Returns a string describing this buffer.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Returns the array that backs this buffer (optional operation). The returned value is the actual array, not a copy, so modifications to the array write through to the buffer.
Subclasses should override this method with a covariant return type to provide the exact type of the array.
Use hasArray
to ensure this method won't throw.
(A separate call to isReadOnly
is not necessary.)
ReadOnlyBufferException | if the buffer is read-only UnsupportedOperationException if the buffer does not expose an array |
---|
Returns the offset into the array returned by array
of the first
element of the buffer (optional operation). The backing array (if there is one)
is not necessarily the same size as the buffer, and position 0 in the buffer is
not necessarily the 0th element in the array. Use
buffer.array()[offset + buffer.arrayOffset()
to access element offset
in buffer
.
Use hasArray
to ensure this method won't throw.
(A separate call to isReadOnly
is not necessary.)
ReadOnlyBufferException | if the buffer is read-only UnsupportedOperationException if the buffer does not expose an array |
---|
Returns the capacity of this buffer.
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 cleared.
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.
Returns true if array
and arrayOffset
won't throw. This method does not
return true for buffers not backed by arrays because the other methods would throw
UnsupportedOperationException
, nor does it return true for buffers backed by
read-only arrays, because the other methods would throw ReadOnlyBufferException
.
Indicates if there are elements remaining in this buffer, that is if
position < limit
.
true
if there are elements remaining in this buffer,
false
otherwise.
Indicates whether this buffer is read-only.
true
if this buffer is read-only, false
otherwise.
Returns the limit of this buffer.
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.
newLimit | the new limit, must not be negative and not greater than capacity. |
---|
IllegalArgumentException | if newLimit is invalid.
|
---|
Marks the current position, so that the position may return to this point
later by calling reset()
.
Sets the position of this buffer.
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.
|
---|
Returns the position of this buffer.
Returns the number of remaining elements in this buffer, that is
limit - position
.
Resets the position of this buffer to the mark
.
InvalidMarkException | if the mark is not set. |
---|
Rewinds this buffer.
The position is set to zero, and the mark is cleared. The content of this buffer is not changed.
Returns a string describing this buffer.