public abstract class Buffer extends Object
| 构造器和说明 |
|---|
Buffer(int mark,
int pos,
int lim,
int cap) |
| 限定符和类型 | 方法和说明 |
|---|---|
abstract Object |
array()
Returns the array that backs this
buffer (optional operation).
|
abstract int |
arrayOffset()
Returns the offset within this buffer's backing array of the first
element of the buffer (optional operation).
|
int |
capacity()
Returns this buffer's capacity.
|
Buffer |
clear()
Clears this buffer.
|
Buffer |
flip()
Flips this buffer.
|
abstract boolean |
hasArray()
Tells whether or not this buffer is backed by an accessible
array.
|
boolean |
hasRemaining()
Tells whether there are any elements between the current position and
the limit.
|
abstract boolean |
isReadOnly()
Tells whether or not this buffer is read-only.
|
int |
limit()
Returns this buffer's limit.
|
Buffer |
limit(int newLimit)
Sets this buffer's limit.
|
Buffer |
mark()
Sets this buffer's mark at its position.
|
int |
position()
Returns this buffer's position.
|
Buffer |
position(int newPosition)
Sets this buffer's position.
|
int |
remaining()
Returns the number of elements between the current position and the
limit.
|
Buffer |
reset()
Resets this buffer's position to the previously-marked position.
|
Buffer |
rewind()
Rewinds this buffer.
|
public final int capacity()
public final int position()
public final Buffer position(int newPosition)
newPosition - The new position value; must be non-negative
and no larger than the current limitIllegalArgumentException - If the preconditions on newPosition do not holdpublic final int limit()
public final Buffer limit(int newLimit)
newLimit - The new limit value; must be non-negative
and no larger than this buffer's capacityIllegalArgumentException - If the preconditions on newLimit do not holdpublic final Buffer mark()
public final Buffer reset()
Invoking this method neither changes nor discards the mark's value.
InvalidMarkException - If the mark has not been setpublic final Buffer clear()
Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
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.
public final Buffer flip()
After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.put(magic); // Prepend header in.read(buf); // Read data into rest of buffer buf.flip(); // Flip buffer out.write(buf); // Write header + data to channel
This method is often used in conjunction with method when transferring data from one place to another.
public final Buffer rewind()
Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately. For example:
out.write(buf); // Write remaining data buf.rewind(); // Rewind buffer buf.get(array); // Copy data into array
public final int remaining()
public final boolean hasRemaining()
public abstract boolean isReadOnly()
public abstract boolean hasArray()
If this method returns true then the array
and arrayOffset methods may safely be invoked.
public abstract Object array()
This method is intended to allow array-backed buffers to be passed to native code more efficiently. Concrete subclasses provide more strongly-typed return values for this method.
Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa.
Invoke the hasArray method before invoking this
method in order to ensure that this buffer has an accessible backing
array.
ReadOnlyBufferException - If this buffer is backed by an array but is read-onlyUnsupportedOperationException - If this buffer is not backed by an accessible arraypublic abstract int arrayOffset()
If this buffer is backed by an array then buffer position p corresponds to array index p + arrayOffset().
Invoke the hasArray method before invoking this
method in order to ensure that this buffer has an accessible backing
array.
ReadOnlyBufferException - If this buffer is backed by an array but is read-onlyUnsupportedOperationException - If this buffer is not backed by an accessible arrayCopyright © 2020. All rights reserved.