本文整理汇总了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;
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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);
}