Java openPrefetchingReadChannel在Google云存储客户端API中不工作
我正在尝试使用Java openPrefetchingReadChannel在Google云存储客户端API中不工作,java,google-app-engine,google-cloud-storage,Java,Google App Engine,Google Cloud Storage,我正在尝试使用GCSInputChannel从bucket中提取对象。正如谷歌开发者教程所说: GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, 1024 * 1024); Prefetching provides is a major performance advantage for most applications, because it allows processing
GCSInputChannel
从bucket中提取对象。正如谷歌开发者教程所说
:
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, 1024 * 1024);
Prefetching provides is a major performance advantage for most applications, because it
allows processing part of the file while more data is being downloaded in the background
in parallel.The third parameter is the size of the prefetch buffer, set in the example
to 1 megabyte.
这对我来说是不可能的。请看一下我的代码片段:
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, 1024);
copy(Channels.newInputStream(readChannel), resp.getOutputStream());
private void copy(InputStream input, OutputStream output) throws IOException {
try {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = input.read(buffer);
while (bytesRead != -1) {
output.write(buffer, 0, bytesRead);
bytesRead = input.read(buffer);
}
} finally {
input.close();
output.close();
}
}
参考:
上述代码应提供上传对象的1KB
数据,但返回对象的全部数据,即8.4KB
。请看截图:
我不知道发生了什么事。需要帮助吗伙计们openPrefetchingReadChannel的第三个参数不是最大读取大小(或限制)。 是预取的内部缓冲区大小。在您的情况下,您可能需要跟踪多少 你读和写,直到达到所需的限度