public abstract class Buffer{
// Invariants: mark <= position <= limit <= capacity
private int mark = -1;
private int position = 0;
private int limit;
private int capacity;
// Used only by direct buffers
// NOTE: hoisted here for speed in JNI GetDirectBufferAddress
long address;
}
他是一种特定的基本类
缓冲区是基本类型元素的线性有序序列,基本属性:容量,限制,位置
容量:所能包含的元素数量
限制:不能读或者写的第一个元素的索引,永远不会负,并且不会大于容量
位置:第一个能读或能写的元素索引,永远不会负,永远不会大于其限制
clear():使缓冲区做好新序列读取操作,将位置设置为0,限制设置为容量
public final Buffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}
flip:使缓冲区做好了新序列信道读取或相对 get 操作的准备:它将限制设置为当前位置,然后将该位置设置为零。
public final Buffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}
rewind:重新读取已包含数据的准备
public final Buffer rewind() {
position = 0;
mark = -1;
return this;
}