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.
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
.