nio
November 20, 2018 · View on GitHub
books
The Layout of a NIO buffer

NIO buffer types
ByteBuffer
Reading from and writing to a ByteBuffer
Reading and writing non-byte types in a ByteBuffer
Reading and writing arrays to a NIO buffer
Reading and writing primitive arrays to a NIO buffer: wrapper buffers
NIO Channels
flip rewind
public final Buffer flip() {
limit = position;
position = 0;// diff
mark = -1;
return this;
}
rewind比flip方法少了position = 0;,比如在 buffer 中填满了数据,就可以使用rewind
因为此时limit = position(limit已经等于position了)
public final Buffer rewind() {
position = 0;
mark = -1;
return this;
}
compact
System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
position(remaining());
limit(capacity());
discardMark();
return this;