本文整理匯總了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;
}