简体   繁体   中英

How to flip a ByteBuffer relative to the mark?

Is there a built-in way, or alternatively, what is the cleanest way, to flip a java NIO ByteBuffer relative to the mark?

That is, flip() sets limit := position and then position := 0 . I would like a flipToMark() routine that sets limit := position and then position := mark .

Flipping clears the mark, so unfortunately buffer.flip().reset() won't work.

How about buffer.limit(buffer.position()).reset() ?

In many cases it may be easier to create a view buffer starting at mark (eg using slice() ), instead of actually setting the mark . In this case you can use the regular flip() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM