What is the purpose of ByteBuffer's flip method? (And why is it called “flip”?)

后端 未结 4 536
眼角桃花
眼角桃花 2020-12-07 13:12

Why does ByteBuffer\'s flip() method called \"flip\"? What is \"flipped\" here? According to apidoc, two successive flips won\'t restore original state, and multiple flips w

4条回答
  •  感情败类
    2020-12-07 13:29

    flip() method makes a buffer ready for a new sequence of channel-write or relative get operations: It sets the limit to the current position and then sets the position to zero.

    Buffer keeps track of the data written into it. Post writing, flip() method is called to switch from writing to reading mode.

提交回复
热议问题