Hi, I'm using Okio. I have a Buffer with 2793 byte...
# squarelibraries
l
Hi, I'm using Okio. I have a Buffer with 2793 bytes which is 21 * 133 bytes. I would like to iterate over the buffer in chunks of size 133 so that I can iterate over it 21 times. How would I achieve this?
z
How do you want to iterate over it? Are you trying to get a bunch of 133-byte byte arrays?
You can call
readByteString(133)
to get 133-byte bytestrings (
ByteString
is essentially an immutable byte array): https://square.github.io/okio/2.x/okio/okio/-buffered-source/read-byte-string.html
l
I need a bunch of 133-byte-Buffer @Zach Klippenstein (he/him) [MOD]
j
You could create a 2nd Buffer and read 133 bytes from the first into the second
Repeatedly
That's fast
l
@jessewilson With "read" do you mean copy or move? I mean I could copy 133 bytes into a 2nd buffer but this wouldn't consume the bytes in the 1st buffer and I would have to worry about that, e.g. skip 133 bytes for 1std buffer after every copy. I hoped there is a built-in function
z
I think he means with the
read
method: https://square.github.io/okio/2.x/okio/okio/-source/read.html The javadoc answers your question.
👍 1
j
@Lilly what would the built-in function do?
l
You could create a 2nd Buffer and read 133 bytes from the first into the second
Thats exactly what I was looking for. I was just not sure what you meant with "read" but the
read
method is consuming the bytes from the original buffer and that'w what I need. I'm happy. Thanks a lot guys 🙏