我有一个ByteString的实例.要从中读取数据,我应该使用它的iterator()方法.
我读了一些数据,然后我决定创建一个视图(一些数据块的独立迭代器).
我不能使用原始迭代器的slice(),因为这会使它无法使用,因为docs说:
After calling this method,one should discard the iterator it was called on,and use only the iterator that was returned. Using the old
iterator is undefined,subject to change,and may result in changes to
the new iterator as well.
所以,似乎我需要在ByteString上调用slice().但是slice()有from和until参数,我不知道.我需要这样的东西:
ByteString originalByteString = ...; // <-- This is my input data ByteIterator originalIterator = originalByteString .iterator(); ... read some data from originalIterator ... int length = 100; // < -- Size of the view int from = originalIterator.currentPosition(); // <-- I need this int until = from + length; ByteString viewOfOriginalByteString = originalByteString.slice(from,until); ByteIterator iteratorForView = viewOfOriginalByteString.iterator(); // <-- This is my goal
更新:
尝试使用duplicate()执行此操作:
ByteIterator iteratorForView = originalIterator.duplicate()._2.take(length);
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。