Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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 openPrefetchingReadChannel在Google云存储客户端API中不工作_Java_Google App Engine_Google Cloud Storage - Fatal编程技术网

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的第三个参数不是最大读取大小(或限制)。 是预取的内部缓冲区大小。在您的情况下,您可能需要跟踪多少 你读和写,直到达到所需的限度