简体   繁体   English

openPrefetchingReadChannel无法在Google云端存储客户端API中使用

[英]openPrefetchingReadChannel is not working in Google Cloud Storage Client API

I am trying to fetch object from bucket using openPrefetchingReadChannel GCSInputChannel . 我试图使用openPrefetchingReadChannel GCSInputChannel从桶中获取对象。 As Google developer tutorial says : 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.

Well this is not happening for me. 嗯这不适合我。 Please have a look at my snippet: 请看一下我的代码:

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

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

Above code should deliver 1KB of data from uploaded object but it is returning the whole data of object ie 8.4KB . 上面的代码应该从上传的对象传递1KB的数据,但它返回对象的整个数据,即8.4KB Please look at the screenshot: 请看截图:

检查Inspect元素的Network选项卡

I am not sure what is happening. 我不确定发生了什么。 Need your help guys 需要你帮助的人

The third argument for openPrefetchingReadChannel is not the max size to read (or limit). openPrefetchingReadChannel的第三个参数不是要读取(或限制)的最大大小。 Is the the internal buffer size for prefetching. 是预取的内部缓冲区大小。 In your case you may want to track how much you read and keep writing until reached the desired limit 在您的情况下,您可能希望跟踪您阅读的数量并继续写入,直到达到所需的限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM