Skip to content

Latest commit

 

History

History
67 lines (44 loc) · 1.65 KB

nio.md

File metadata and controls

67 lines (44 loc) · 1.65 KB

nio

books

The Layout of a NIO buffer

NioBuffer

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;
    }

rewindflip方法少了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;