openPrefetchingReadChannel没有在谷歌云存储客户端API工作(openPre

2019-10-20 21:54发布

我试图使用水桶取对象openPrefetchingReadChannel GCSInputChannel 。 作为Google developer tutorial says

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();
    }
  }

参考: https://code.google.com/p/appengine-gcs-client/source/browse/trunk/java/example/src/com/google/appengine/demos/GcsExampleServlet.java

上面的代码应该提供1KB从上传的对象数据的,但它返回的对象即整个数据8.4KB 。 请看截图:

我不知道发生了什么。 需要你的帮助球员

Answer 1:

对于openPrefetchingReadChannel第三个参数是不是最大尺寸来读取(或限制)。 是用于预取的内部缓冲区大小。 你的情况可能要跟踪你读了多少,并继续写,直到达到所需的极限



文章来源: openPrefetchingReadChannel is not working in Google Cloud Storage Client API