Reputation: 587
How to implement seek() function in BufferSink (or BufferedSource) in OKHttp?
We all know that in Java, the RandomAccessFile class has a method seek(long), which enable us to start reading/writing a file from a specific position, and the bytes before the postion will be discarded. Is there any similar methods in OKHttp?
I have noticed that there is a method in BufferedSink:
write(byteString: ByteString, offset: Int, byteCount: Int)
But unfortunately the parameter "offset" aceepts only type int, not type long, which has some limit when transmitting large files.
Upvotes: 2
Views: 826
Reputation: 40593
The API you're looking for is BufferedSource.skip()
.
In Okio 3.0 (coming soon) we’re adding a new Cursor
class that'll make skip()
faster if the underlying source is a File
.
https://github.com/square/okio/issues/889
Upvotes: 3
Reputation: 891
I am using Okio.buffer to read an image file from the assets folder like this:
BufferedSource img = Okio.buffer(Okio.source(getAssets().open("image.jpg")));
byte[] image = img.readByteArray();
Upvotes: -1