Creates a read-only view of this buffer.
Creates a read-only view of this buffer.
Returns this buffer's capacity.
Returns this buffer's capacity.
Clears this buffer.
Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded. No values in the buffer are actually cleared, but this is typically used before putting new values into a buffer, after all its contents have been processed.
If the buffer's current values have not been completely processed, then the compact
method may be more
appropriate.
Compacts this buffer (optional operation).
Compacts this buffer (optional operation). The bytes between the buffer's current position and its limit, if any,
are copied to the beginning of the buffer. That is, the byte at index p = position()
is copied to index 0
, the
byte at index p + 1
is copied to index 1
, and so forth until the byte at index limit() - 1
is copied to index
n = limit() - 1 - p
. The buffer's position is then set to n+1
and its limit is set to its capacity. The mark,
if defined, is discarded.
The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.
Invoke this method after writing data from a buffer in case the write was incomplete.
Dies with ReadOnlyBufferException
if this buffer is read-only.
Creates a new buffer that shares this buffer's content.
Creates a new buffer that shares this buffer's content. The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer.
Flips this buffer.
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded. After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations.
This method is often used in conjunction with the compact
method when transferring data from one place to
another.
Absolute get of a single element.
Absolute get of a single element. Reads the element at the given index. The position does not change.
Dies with IndexOutOfBoundsException
if the index is negative or not smaller than the limit.
Relative get of a single element.
Relative get of a single element. Reads the element at the position and increments the position.
Dies with BufferUnderflowException
If there are no elements remaining.
Relative get of multiple elements.
Relative get of multiple elements.
Reads up to the specified number of elements from the current position. If fewer than maxLength
elements are
remaining, then all the remaining elements are read. The position is incremented by the number of elements read.
Defaults to Int.MaxValue
, meaning all remaining elements will be read.
Indicates if this buffer is backed by an array on the heap.
Indicates if this buffer is backed by an array on the heap.
The underlying array can be used in a safe way via the withArray
method.
Indicates whether there are any elements between this buffer's position and its limit.
Indicates whether there are any elements between this buffer's position and its limit.
Indicates if this buffer was directly allocated.
Indicates if this buffer was directly allocated.
Returns true for directly allocated ByteBuffer
s and view buffers created from them.
Indicates if this buffer is read-only.
Indicates if this buffer is read-only.
Calling any put methods on a read-only buffer with throw ReadOnlyBufferException
.
Sets this buffer's limit.
Sets this buffer's limit.
Dies with IllegalArgumentException
if the new limit is outside the bounds.
Must be >= 0 and <= this buffer's capacity.
Returns this buffer's limit.
Returns this buffer's limit.
Sets this buffer's mark to the current position.
Sets this buffer's mark to the current position.
Moves this buffer's limit forward or backwards by a delta.
Moves this buffer's limit forward or backwards by a delta.
The number of elements to move, negative to move backwards.
The new limit.
Moves this buffer's position forward or backwards by a delta.
Moves this buffer's position forward or backwards by a delta.
The number of elements to move, negative to move backwards.
The new position.
The byte order used for reading multiple byte values.
The byte order used for reading multiple byte values.
Also the byte order used any view buffers created from this buffer.
Sets this buffer's position.
Sets this buffer's position.
Dies with IllegalArgumentException
if the new position is outside the bounds.
Must be >= 0 and <= the current limit.
Returns this buffer's position.
Returns this buffer's position.
Absolute put of a single element.
Absolute put of a single element. Writes the element at the specified index. The position does not change.
Dies with IndexOutOfBoundsException
if the index is negative or not smaller than the limit. Dies with
ReadOnlyBufferException
if this is a read-only buffer.
Relative put of a single element.
Relative put of a single element. Writes the element at the position and increments the position.
Dies with BufferOverflowException
if there are no elements remaining. Dies with ReadOnlyBufferException
if this
is a read-only buffer.
Relative put of multiple elements.
Relative put of multiple elements. Writes as many elements as can fit in remaining buffer space, returning any elements that did not fit.
The remaining elements that could not fit in this buffer, if any.
Tries to put an entire chunk in this buffer, possibly overflowing.
Tries to put an entire chunk in this buffer, possibly overflowing.
putChunk
is a safe public variant of this that won't overflow.
Returns the number of elements between this buffer's position and its limit.
Returns the number of elements between this buffer's position and its limit.
Resets the position to the previously set mark.
Resets the position to the previously set mark. A mark must be set before calling this.
Dies with InvalidMarkException
if a mark has not previously been set.
Rewinds this buffer.
Rewinds this buffer. The position is set to zero and the mark is discarded. Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately.
Creates a new buffer whose content is a shared subsequence of this buffer's content.
Creates a new buffer whose content is a shared subsequence of this buffer's content. The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer.
Perform effects using this buffer's underlying array directly.
Perform effects using this buffer's underlying array directly. Because only some buffers are backed by arrays, two
cases must be handled. Ideally, the same result is produced in each case, with the hasArray
variant just being
more efficient.
For the hasArray
case, the function is provided the backing array itself and an offset within that array which
contains the first element of this buffer. Elements in the array before the offset are not contained in this
buffer.
The effect to perform if this buffer is not backed by an array.
The effect to perform if this buffer is backed by an array.
Provides the underlying Java character buffer for use in an effect.
Provides the underlying Java character buffer for use in an effect.
This is useful when using Java APIs that require a Java character buffer to be provided.
The effect value constructed by f
using the underlying buffer.
A mutable buffer of characters.