- Direct Known Subclasses:
SmallByteBuffer,SmallDoubleBuffer,SmallFloatBuffer,SmallIntBuffer,SmallLongBuffer,SmallShortBuffer
Buffer. All implementations are
backed by a BigByteBuffer. "Small" refers to the fact that these
buffers are indexed by ints rather than longs.
Differences from Buffer include:
- mark and reset are not supported
- read-only is not supported
- byte order is preserved in
duplicate()andslice().
- Author:
- biteytech@protonmail.com, adapted from
Buffer
-
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Returns this buffer's capacity.clear()Clears this buffer.abstract SmallBufferCreates a new buffer that shares this buffer's content.flip()Flips this buffer.booleanTells whether there are any elements between the current position and the limit.intlimit()Returns this buffer's limit.limit(int newLimit) Sets this buffer's limit.order()Retrieves this buffer's byte order.intposition()Returns this buffer's position.position(int newPosition) Sets this buffer's position.intReturns the number of elements between the current position and the limit.abstract SmallBufferslice()Creates a new buffer whose content is a shared subsequence of this buffer's content.unwrap()Returns the underlyingbuffer.
-
Method Details
-
unwrap
Returns the underlyingbuffer.- Returns:
- the underlying buffer.
-
position
public int position()Returns this buffer's position.- Returns:
- The position of this buffer
-
limit
public int limit()Returns this buffer's limit.- Returns:
- The limit of this buffer
-
capacity
public int capacity()Returns this buffer's capacity.- Returns:
- The capacity of this buffer
-
position
Sets this buffer's position.- Parameters:
newPosition- The new position value; must be non-negative and no larger than the current limit- Returns:
- this buffer
- Throws:
IllegalArgumentException- If the preconditions onnewPositiondo not hold
-
limit
Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit.- Parameters:
newLimit- The new limit value; must be non-negative and no larger than this buffer's capacity- Returns:
- this buffer
- Throws:
IllegalArgumentException- If the preconditions onnewLimitdo not hold
-
remaining
public int remaining()Returns the number of elements between the current position and the limit.- Returns:
- The number of elements remaining in this buffer
-
hasRemaining
public boolean hasRemaining()Tells whether there are any elements between the current position and the limit.- Returns:
trueif, and only if, there is at least one element remaining in this buffer
-
order
Retrieves this buffer's byte order.The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer.
- Returns:
- This buffer's byte order
-
duplicate
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 and limit values will be independent.
The new buffer's capacity, limit, position, and byte order values will be identical to those of this buffer. The new buffer will be direct if, and only if, this buffer is direct.
- Returns:
- The new buffer
-
slice
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 and limit values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of elements remaining in this buffer, and the byte order will be the same as this buffer. The new buffer will be direct if, and only if, this buffer is direct.
- Returns:
- The new buffer
-
clear
Clears this buffer. The position is set to zero and the limit is set to the capacity.This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
- Returns:
- This buffer
-
flip
Flips this buffer. The limit is set to the current position and then the position is set to zero.- Returns:
- This buffer
-