當前位置: 首頁>>代碼示例>>Java>>正文


Java File.getDownloadUrl方法代碼示例

本文整理匯總了Java中com.google.api.services.drive.model.File.getDownloadUrl方法的典型用法代碼示例。如果您正苦於以下問題:Java File.getDownloadUrl方法的具體用法?Java File.getDownloadUrl怎麽用?Java File.getDownloadUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.services.drive.model.File的用法示例。


在下文中一共展示了File.getDownloadUrl方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileContent

import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
private InputStream getFileContent(File driveFile, Drive driveService) throws IOException {
	if (driveFile.getDownloadUrl() != null && driveFile.getDownloadUrl().length() > 0) {

		GenericUrl downloadUrl = new GenericUrl(driveFile.getDownloadUrl());

		HttpResponse resp = driveService.getRequestFactory().buildGetRequest(downloadUrl).execute();
		return resp.getContent();
	} else {
		//return an empty input stream
		return new ByteArrayInputStream("".getBytes());
	}

}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:14,代碼來源:GoogleDriveFileStorage.java

示例2: delete

import com.google.api.services.drive.model.File; //導入方法依賴的package包/類
@Override
public void delete(Entry entry) {
    LogUtil.log(getClass().getSimpleName(), "delete()");

    SyncInfo info = new SyncInfo();
    info.setTitle(entry.uuid);
    info.setSyncService(SyncService.GoogleDrive.ordinal());
    info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis());
    info.setSyncStatus(SyncStatus.DELETE);
    SyncInfoDao.saveData(info);

    File file = getEntry(entry.uuid);

    if (file != null && file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
        try {
            service.files().delete(file.getId()).execute();

            info.setSyncStatus(SyncStatus.OK);
            SyncInfoDao.saveData(info);

        } catch (IOException e) {
            // An error occurred.
            e.printStackTrace();
            if (!BuildConfig.DEBUG) Crashlytics.logException(e);
        }
    } else {
        LogUtil.log(getClass().getSimpleName(), "file == null: " + (file == null));
        if (!BuildConfig.DEBUG) Crashlytics.log("file == null in DriveSyncService#delete(Entry): " + (file == null));

        info.setSyncStatus(SyncStatus.OK);
        SyncInfoDao.saveData(info);
    }
}
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:34,代碼來源:DriveSyncService.java

示例3: download

import com.google.api.services.drive.model.File; //導入方法依賴的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;
}
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:48,代碼來源:DriveSyncService.java


注:本文中的com.google.api.services.drive.model.File.getDownloadUrl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。