本文整理汇总了Java中com.google.api.client.http.HttpResponse.download方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.download方法的具体用法?Java HttpResponse.download怎么用?Java HttpResponse.download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.download方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: download
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
private byte[] download(String downloadUrl) throws IOException {
HttpRequest get = gdriveConnectionRule.getDrive().getRequestFactory()
.buildGetRequest(new GenericUrl(downloadUrl));
HttpResponse response = get.execute();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.download(baos);
return baos.toByteArray();
}
示例2: download
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@Override
public Entry download(String uuid) {
LogUtil.log(getClass().getSimpleName(), "download()");
File file = getEntry(uuid);
if (file != null && file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
try {
HttpResponse resp =
service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
.execute();
ByteArrayOutputStream os = new ByteArrayOutputStream();
resp.download(os);
LogUtil.log(getClass().getSimpleName(), "Download: " + os.toString("UTF-8"));
// process input stream
Entry entry = EntryHelper.fromJson(os.toString("UTF-8"));
// close stream to prevent a memory leak
os.close();
if (entry != null) {
LogUtil.log(getClass().getSimpleName(), "entry != null");
SyncInfo info = new SyncInfo();
info.setTitle(entry.uuid);
info.setSyncService(SyncService.GoogleDrive.ordinal());
info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis());
info.setSyncStatus(SyncStatus.OK);
info.setRevision(String.valueOf(file.getVersion()));
SyncInfoDao.saveData(info);
} else
LogUtil.log(getClass().getSimpleName(), "entry == null");
return entry;
} catch (Exception e) {
LogUtil.log(getClass().getSimpleName(), "Exception in download() - " + e.getMessage());
if (!BuildConfig.DEBUG) Crashlytics.logException(e);
}
} else {
LogUtil.log(getClass().getSimpleName(), "file == null: " + (file == null));
if (!BuildConfig.DEBUG) Crashlytics.log("file == null in DriveSyncService#download(Entry): " + (file == null));
}
return null;
}