I have an instance ByteString. To read data from it, I have to use a method iterator().
I read some data and then decided that I needed to create a view (a separate iterator of some piece of data).
I can't use the slice()original iterator because it would make it unusable because the docs say that:
After calling this method, you should discard the iterator to which it was called, and use only the returned iterator. Using the old iterator is undefined, it can be modified and can lead to changes in the new iterator.
So it seems to me that I need to call slice()on ByteString. But it slice()has parameters fromand until, and I do not know from. I need something like this:
ByteString originalByteString = ...;
ByteIterator originalIterator = originalByteString .iterator();
...
read some data from originalIterator
...
int length = 100;
int from = originalIterator.currentPosition();
int until = from + length;
ByteString viewOfOriginalByteString = originalByteString.slice(from, until);
ByteIterator iteratorForView = viewOfOriginalByteString.iterator();
Update:
Tried to do this with duplicate():
ByteIterator iteratorForView = originalIterator.duplicate()._2.take(length);
source
share