1
我正嘗試使用openPrefetchingReadChannelGCSInputChannel
從存儲桶中獲取對象。由於Google developer tutorial says
:openPrefetchingReadChannel無法在Google雲端存儲客戶端API中工作
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
的全部數據。請看截圖:
我不知道發生了什麼。需要你的幫助的人