NIO中的Buffer

时间:2023-03-09 19:46:24
NIO中的Buffer
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

 public final Buffer clear() {
position = 0;
limit = capacity;
mark = -1;
return this;
}

flip

 public final Buffer flip() {
limit = position;
position = 0;
mark = -1;
return this;
}

rewind

public final Buffer rewind() {
position = 0;
mark = -1;
return this;
}