[英]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?是否有内置的方法,或者最干净的方法是相对于标记翻转 java NIO ByteBuffer?
That is, flip()
sets limit := position
and then position := 0
.也就是说, flip()
设置limit := position
,然后position := 0
。 I would like a flipToMark()
routine that sets limit := position
and then position := mark
.我想要一个flipToMark()
例程,它设置limit := position
然后position := mark
。
Flipping clears the mark, so unfortunately buffer.flip().reset()
won't work.翻转清除标记,因此不幸的是buffer.flip().reset()
将不起作用。
How about buffer.limit(buffer.position()).reset()
? 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
.在许多情况下,创建一个从mark
开始的视图缓冲区可能更容易(例如使用slice()
),而不是实际设置mark
。 In this case you can use the regular flip()
method.在这种情况下,您可以使用常规的flip()
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.