谷歌云存储当使用java api下载大于chunksize的文件时,ZLIB输入流的意外结束

时间:2014-09-17 10:47:14

标签: java google-cloud-storage

我试图从Play商店下载使用java api在存储桶中访问的评论(消息末尾的详细信息)。对于在压缩时大于块大小的审阅文件,我得到以下异常:

java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at com.google.api.client.util.ByteStreams.copy(ByteStreams.java:51)
at com.google.api.client.util.IOUtils.copy(IOUtils.java:94)
at com.google.api.client.util.IOUtils.copy(IOUtils.java:63)
at com.google.api.client.googleapis.media.MediaHttpDownloader.executeCurrentRequest(MediaHttpDownloader.java:247)
at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:199)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAndDownloadTo(AbstractGoogleClientRequest.java:553)
at com.google.api.services.storage.Storage$Objects$Get.executeMediaAndDownloadTo(Storage.java:4540)
at com.google.api.services.storage.Storage$Objects$Get$executeMediaAndDownloadTo.call(Unknown Source)

我使用的代码是:

private void saveObject(StorageObject object) {
    try {
        System.out.println("Getting object data");
        FileOutputStream fos = new FileOutputStream (new File(object.getName()));

        Storage.Objects.Get getObject =
            storage.objects().get("pubsite_prod_rev_XXXXX", object.getName());

        // setting the chunksize to a small value fails pretty much on all files
        getObject.getMediaHttpDownloader().setDirectDownloadEnabled(false).setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE)

        // setting the chunksize to larger value allows me to download some of the files but fails on larger ones
        //getObject.getMediaHttpDownloader().setDirectDownloadEnabled(false).setChunkSize(MediaHttpDownloader.MAXIMUM_CHUNK_SIZE)


        getObject.executeMediaAndDownloadTo(fos);
        fos.close();
    } catch(Exception e) {
        System.err.println("Error downloading " + object.getName());
        e.printStackTrace();
    }

我可以使用gsutil下载文件,所以它似乎是MediaHttpDownloader中的分块实现的问题。

我正在使用java 7和以下的库

compile group: 'com.google.api-client', name: 'google-api-client', version: '1.19.0'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.19.0'
compile group: 'com.google.apis', name: 'google-api-services-storage', version: 'v1beta2-rev56-1.19.0'

此外,我正在使用常规但不知道这会如何影响该问题,因为错误是在谷歌库中。

感谢您的帮助

安德烈

0 个答案:

没有答案