Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在OKHttp的BufferedSink(或BufferedSource)中实现seek()函数?_Java_Android_Okhttp_Okio - Fatal编程技术网

Java 如何在OKHttp的BufferedSink(或BufferedSource)中实现seek()函数?

Java 如何在OKHttp的BufferedSink(或BufferedSource)中实现seek()函数?,java,android,okhttp,okio,Java,Android,Okhttp,Okio,如何在OKHttp的BufferSink(或BufferedSource)中实现seek()函数 我们都知道,在Java中,RandomAccessFile类有一个方法,它使我们能够从特定位置开始读/写文件,并且位置之前的字节将被丢弃。OKHttp中有类似的方法吗 我注意到BufferedSink中有一个方法: write(byteString: ByteString, offset: Int, byteCount: Int) 但不幸的是,参数“offset”只接受int类型,而不是long类

如何在OKHttp的BufferSink(或BufferedSource)中实现seek()函数

我们都知道,在Java中,RandomAccessFile类有一个方法,它使我们能够从特定位置开始读/写文件,并且位置之前的字节将被丢弃。OKHttp中有类似的方法吗

我注意到BufferedSink中有一个方法:

write(byteString: ByteString, offset: Int, byteCount: Int)

但不幸的是,参数“offset”只接受int类型,而不是long类型,这在传输大文件时有一定的限制。

我使用Okio.buffer从资产文件夹中读取图像文件,如下所示:

 BufferedSource img = Okio.buffer(Okio.source(getAssets().open("image.jpg")));

 byte[] image = img.readByteArray();

您正在查找的API是
BufferedSource.skip()

在Okio 3.0(即将推出)中,我们添加了一个新的
游标
类,如果底层源代码是
文件
,它将使
跳过()
更快


如果没有服务器端的额外支持,HTTP流将不会是随机访问。当你试图寻找过去的两个游戏时,你可能想考虑另一个协议,比如其他协议。