从Google云端硬盘读取文件为InputStream,抛出OutOfMemoryError

时间:2017-08-04 14:17:55

标签: java google-app-engine google-drive-api

我想从Google云端硬盘读取文件(70MB),代码如下:

运营环境:Appengine标准环境。

Credential credential = getCredentialManager().get(SessionUtil.getUserKey());
Drive drive = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
InputStream inputStream  = drive.files().get({fileId}).executeMediaAsInputStream();

错误日志:

Caused by: java.lang.OutOfMemoryError: Java heap space
    at com.google.protobuf.ByteString.toByteArray(ByteString.java:615)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertFromPb(URLFetchServiceImpl.java:247)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:61)
    at com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:37)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:972)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMedia(AbstractGoogleClientRequest.java:380)
    at com.google.api.services.drive.Drive$Files$Get.executeMedia(Drive.java:2727)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAsInputStream(AbstractGoogleClientRequest.java:523)
    at com.google.api.services.drive.Drive$Files$Get.executeMediaAsInputStream(Drive.java:2722)
    at com.deepnet.idigisign.services.plugin.goolgeDrive.GoogleDrive.file(GoogleDrive.java:178)

当我将文件作为InputStream读取时,为什么存在toByteArray()方法。 有什么身体可以帮助我吗?

0 个答案:

没有答案