当前位置: 首页>>代码示例>>Java>>正文


Java DbxDownloader.download方法代码示例

本文整理汇总了Java中com.dropbox.core.DbxDownloader.download方法的典型用法代码示例。如果您正苦于以下问题:Java DbxDownloader.download方法的具体用法?Java DbxDownloader.download怎么用?Java DbxDownloader.download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.dropbox.core.DbxDownloader的用法示例。


在下文中一共展示了DbxDownloader.download方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: downloadFile

import com.dropbox.core.DbxDownloader; //导入方法依赖的package包/类
/**
 * download dropbox file locally
 * @param dboxFilename
 * @return downloaded local temp file
 * @throws IOException
 * @throws DownloadErrorException
 * @throws DbxException
 */
public String downloadFile(String dboxFilename) throws IOException, DownloadErrorException, DbxException {
	File tmpFile = File.createTempFile("dropbox-downloaded-file", ".tmp"); 
	DbxDownloader<FileMetadata> download = dboxClient.files().download(dboxFilename);
	OutputStream fOut = new FileOutputStream(tmpFile);
	download.download(fOut );
	String filePath = tmpFile.getAbsolutePath();
	fOut.close();
	return filePath;
}
 
开发者ID:boly38,项目名称:mongodbdump-java-wrapper,代码行数:18,代码来源:DropboxServiceImpl.java

示例2: getEvent

import com.dropbox.core.DbxDownloader; //导入方法依赖的package包/类
@Override
public Optional<MotionEvent> getEvent(String id) {
    MotionEvent motionEvent = motionEventStore.get(id);
    try {
        String dropboxPath = "/motion_events/" + concurrentDateFormatAccess.convertDateToString(motionEvent.getTimestamp());
        DbxDownloader<FileMetadata> dbxDownloader = dbxClientV2.files().download(dropboxPath + "/" + motionEvent.getId() + ".jpg");
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        dbxDownloader.download(byteArrayOutputStream);
        return Optional.of(new MotionEvent(id, motionEvent.getTimestamp(), byteArrayOutputStream.toByteArray()));
    } catch (Exception e) {
        log.error("Problem retrieving motion event: " + motionEvent.getId() + " from dropbox.", e);
        return Optional.empty();
    }
}
 
开发者ID:chriskearney,项目名称:eyeballs,代码行数:15,代码来源:DropBoxMotionEventPersistence.java

示例3: downloadFile

import com.dropbox.core.DbxDownloader; //导入方法依赖的package包/类
public void downloadFile(final String path, final OutputStream outputStream) {
    try {
        final DbxDownloader<FileMetadata> downloader = client.files().download(path);

        downloader.download(outputStream);
    } catch (final Exception ex) {
        LOG.error("Failed to download from Dropbox: " + path, ex);
        throw new DSyncClientException(ex);
    }
}
 
开发者ID:yuriytkach,项目名称:dsync-client,代码行数:11,代码来源:DropboxService.java

示例4: testUploadAndDownload

import com.dropbox.core.DbxDownloader; //导入方法依赖的package包/类
private void testUploadAndDownload(DbxClientV2 client) throws Exception {
    byte [] contents = ITUtil.randomBytes(1024);
    String filename = "testUploadAndDownload.dat";
    String path = ITUtil.path(getClass(), "/" + filename);

    FileMetadata metadata = client.files().uploadBuilder(path)
        .withAutorename(false)
        .withMode(WriteMode.ADD)
        .withMute(true)
        .uploadAndFinish(new ByteArrayInputStream(contents));

    assertEquals(metadata.getName(), filename);
    assertEquals(metadata.getPathLower(), path.toLowerCase());
    assertEquals(metadata.getSize(), contents.length);

    Metadata actual = client.files().getMetadata(path);
    assertTrue(actual instanceof FileMetadata, actual.getClass().getCanonicalName());
    assertEquals(actual, metadata);

    DbxDownloader<FileMetadata> downloader = client.files().download(path);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    downloader.download(out);

    byte [] actualContents = out.toByteArray();
    FileMetadata actualResult = downloader.getResult();

    assertEquals(actualResult, metadata);
    assertEquals(actualContents, contents);

    Metadata deleted = client.files().delete(path);
    assertEquals(deleted, metadata);
}
 
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:33,代码来源:DbxClientV2IT.java

示例5: testRetryDownload

import com.dropbox.core.DbxDownloader; //导入方法依赖的package包/类
@Test
public void testRetryDownload() throws Exception {
    HttpRequestor mockRequestor = mock(HttpRequestor.class);
    DbxRequestConfig config = createRequestConfig()
        .withAutoRetryEnabled(3)
        .withHttpRequestor(mockRequestor)
        .build();

    DbxClientV2 client = new DbxClientV2(config, "fakeAccessToken");
    FileMetadata expectedMetadata = constructFileMetadate();
    byte [] expectedBytes = new byte [] { 1, 2, 3, 4 };

    // 503 once, then return 200
    HttpRequestor.Uploader mockUploader = mockUploader();
    when(mockUploader.finish())
        .thenReturn(createEmptyResponse(503))
        .thenReturn(createDownloaderResponse(expectedBytes, serialize(expectedMetadata)));
    when(mockRequestor.startPost(anyString(), anyHeaders()))
        .thenReturn(mockUploader);

    DbxDownloader<FileMetadata> downloader = client.files().download(expectedMetadata.getId());

    // should have been attempted twice
    verify(mockRequestor, times(2)).startPost(anyString(), anyHeaders());

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    FileMetadata actualMetadata = downloader.download(bout);
    byte [] actualBytes = bout.toByteArray();

    assertEquals(actualBytes, expectedBytes);
    assertEquals(actualMetadata, expectedMetadata);
}
 
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:33,代码来源:DbxClientV2Test.java


注:本文中的com.dropbox.core.DbxDownloader.download方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。