本文整理汇总了Java中com.dropbox.core.DbxDownloader类的典型用法代码示例。如果您正苦于以下问题:Java DbxDownloader类的具体用法?Java DbxDownloader怎么用?Java DbxDownloader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbxDownloader类属于com.dropbox.core包,在下文中一共展示了DbxDownloader类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
protected Bell start(Bell bell) {
return new ThreadBell() {
public Object run() throws Exception {
/*Issue #25
Modified by: Dhruva Kumar Srinivasa
Comments: Dropbox v2 API returns a DbxDownloader instance. Call download on the DbxDownloader object, passing an output stream as a parameter*/
DbxDownloader<FileMetadata> downloader = session.client.files().download(
source().path.toString());
downloader.download(asOutputStream());
//End changes for Issue #21
finish();
return null;
} public void fail(Throwable t) {
finish();
}
}.startOn(initialize().and(bell));
}
示例2: read
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final DownloadBuilder builder = new DbxUserFilesRequests(session.getClient()).downloadBuilder(file.getAbsolute());
if(status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
builder.range(range.getStart());
}
final DbxDownloader<FileMetadata> downloader = builder.start();
return downloader.getInputStream();
}
catch(DbxException e) {
throw new DropboxExceptionMappingService().map("Download {0} failed", e, file);
}
}
示例3: readFile
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
/**
*
* @param path The path in dropbox there the file exists
* @return java.io.InputStream with file contents
* @throws DbxException
*/
@Override
public InputStream readFile(String path)
throws DbxException {
DbxDownloader downloader = client.files().downloadBuilder(path).start();
InputStream in = downloader.getInputStream();
return in;
}
示例4: 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;
}
示例5: 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();
}
}
示例6: 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);
}
}
示例7: getServerSubscriptions
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
private Map<String, String> getServerSubscriptions() throws DbxException {
final Map<String, String> subscriptions = new HashMap<>();
DbxDownloader downloader = null;
try {
// Get subscription file and process it
downloader = client.files().download(SUBSCRIPTION_LIST_FILE_PATH);
Scanner scanner = new Scanner(downloader.getInputStream(), "UTF-8").useDelimiter("\\A");
String[] lines = (scanner.hasNext() ? scanner.next() : "").split("\\r\\n?|\\n");
for (String line : lines) {
String[] parts = line.split("\\s", 2);
// Each line has to have at least an URL, title is optional
if (line.startsWith("http")) {
final Podcast podcast = new Podcast(parts.length > 1 ? parts[1] : null, parts[0]);
subscriptions.put(podcast.getUrl(), podcast.getName());
}
}
} catch (DownloadErrorException dee) {
// If our feed file does not yet exist, return empty map
// Otherwise:
if (!dee.errorValue.isPath())
throw dee;
} finally {
if (downloader != null)
downloader.close();
}
return subscriptions;
}
开发者ID:salema,项目名称:Podcatcher-Deluxe-Android-Studio,代码行数:30,代码来源:DropboxPodcastListSyncController.java
示例8: load
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
@Override
public Result load(Request request, int networkPolicy) throws IOException {
try {
DbxDownloader<FileMetadata> downloader =
mDbxClient.files().getThumbnailBuilder(request.uri.getPath())
.withFormat(ThumbnailFormat.JPEG)
.withSize(ThumbnailSize.W1024H768)
.start();
return new Result(downloader.getInputStream(), Picasso.LoadedFrom.NETWORK);
} catch (DbxException e) {
throw new IOException(e);
}
}
示例9: 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);
}
示例10: 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);
}
示例11: getFileDownloader
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
public DbxDownloader<Files.FileMetadata> getFileDownloader(String path) throws DbxException {
return dropbox.dbxClientV2.files.downloadBuilder(path).start();
}
示例12: start
import com.dropbox.core.DbxDownloader; //导入依赖的package包/类
/**
* Issues the download request using this builder's request parameters and returns a {@link
* DbxDownloader} for reading the response body.
*
* Callers should fully read the response body using {@link DbxDownloader#getInputStream} and
* close the downloader afterwards (see {@link DbxDownloader#close}). This will allow for proper
* resource deallocation and connection re-use..
*
* See {@link #download} convenience method for a simpler way to complete the request.
*
* @return {@link DbxDownloader} used to download data and read the response.
*
* @throws DbxException if an error occursing issuing the request
*/
public abstract DbxDownloader<R> start() throws DbxException;