执行对象下载时的Google Storage JSON API NullPointException

时间:2014-07-22 02:36:59

标签: google-cloud-storage

当我尝试使用以下代码下载Storage对象时遇到NullPointException:

    Storage.Objects.Get getObject = storage.objects().get(BUCKET_LOG, entity);
    getObject.getMediaHttpDownloader().setDirectDownloadEnabled(true);//directly download, which is recommended for non AppEngine Apps.

堆栈跟踪是:         at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:186) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAndDownloadTo(AbstractGoogleClientRequest.java:553) at com.google.api.services.storage.Storage$Objects$Get.executeMediaAndDownloadTo(Storage.java:4606) at com.alibaba.intl.google.adwords.util.GoogleStorageUtil.downloadStorageObject(GoogleStorageUtil.java:149)

所以我看了 MediaHttpDownloader 的第186行,发现了这个:

    mediaContentLength = response.getHeaders().getContentLength();

嗯,这是问题,方法 getContentLength 可能会返回null值,而变量mediaContentLength的类型,但不是

HttpHeaders

类快照的一部分
   public final Long getContentLength() {
       return getFirstHeaderValue(contentLength);
   }

   /**Returns the first header value based on the given internal list value.*/
   private <T> T getFirstHeaderValue(List<T> internalValue) {
       return internalValue == null ? null : internalValue.get(0);
   }

我正在使用Java Library for AdWords API V201402。

0 个答案:

没有答案