Package com.dropbox.core.v2
Class DbxDownloadStyleBuilder<R>
java.lang.Object
com.dropbox.core.v2.DbxDownloadStyleBuilder<R>
- Type Parameters:
R- The return type of theDbxDownloader
- Direct Known Subclasses:
DbxAppGetSharedLinkFileBuilder,DbxAppGetThumbnailV2Builder,DbxUserGetSharedLinkFileBuilder,DbxUserGetThumbnailV2Builder,DocsDownloadBuilder,DownloadBuilder,DownloadZipBuilder,ExportBuilder,GetPhotoBuilder,GetPreviewBuilder,GetThumbnailBuilder
The common interface for all builders associated with download style methods. After setting any
optional request parameters, use
start or download(java.io.OutputStream) to initiate the request.
Example usage:
// set our optional request parameters
DbxDownloader<FileMetadata> downloader = client.files.getThumbnailBuilder("/test.png")
.format(ThumbnailFormat.png())
.size(ThumbnailSize.w64h64())
.start();
FileMetadata metadata = downloader.getResult();
FileOutputStream out = new FileOutputStream(outFile);
try {
// set our upload content
InputStream in = downloader.getInputStream();
// read from in, write to out
} finally {
downloader.close();
out.close();
}
Same example using the download(java.io.OutputStream) convenience method:
FileOutputStream out = new FileOutputStream(outFile);
try {
// set our optional request parameters
FileMetadata metadata = client.files.getThumbnailBuilder("/test.png")
.format(ThumbnailFormat.png())
.size(ThumbnailSize.w64h64())
.download(out);
} finally {
out.close();
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondownload(OutputStream out) Convenience method forDbxDownloader.download(OutputStream):protected List<HttpRequestor.Header> range(long start) Sets the partial byte range to download.range(long start, long length) Sets the partial byte range to download.abstract DbxDownloader<R> start()Issues the download request using this builder's request parameters and returns aDbxDownloaderfor reading the response body.
-
Constructor Details
-
DbxDownloadStyleBuilder
protected DbxDownloadStyleBuilder()
-
-
Method Details
-
getHeaders
-
start
Issues the download request using this builder's request parameters and returns aDbxDownloaderfor reading the response body. Callers should fully read the response body usingDbxDownloader.getInputStream()and close the downloader afterwards (seeDbxDownloader.close()). This will allow for proper resource deallocation and connection re-use.. Seedownload(java.io.OutputStream)convenience method for a simpler way to complete the request.- Returns:
DbxDownloaderused to download data and read the response.- Throws:
DbxException- if an error occursing issuing the request
-
range
Sets the partial byte range to download. Only the specified bytes of the content will be downloaded. The HTTP Range header will be set for this request. Ifstartis greater than the length of the content, the range request will be ignored and server will return the entire contents. Iflengthextends beyond the end of the cont`ent, the server will return all bytes fromstartuntil the end of the content.- Parameters:
start- index of first byte in range (index starts at 0)length- number of bytes to download starting atstart- Returns:
- this builder
- Throws:
IllegalArgumentException- ifstartorlengthare negative
-
range
Sets the partial byte range to download. Only bytes fromstart(inclusive) until the end of the content will be downloaded. The HTTP Range header will be set for this request. Ifstartis greater than the length of the content, the range request will be ignored and server will return the entire contents.- Parameters:
start- index of first byte in range (index starts at 0). All following bytes in the content will be downloaded.- Returns:
- this builder
- Throws:
IllegalArgumentException- ifstartis negative
-
download
Convenience method forDbxDownloader.download(OutputStream):builder.start().download(out);- Parameters:
out-OutputStreamto write response body to- Returns:
- Response from server
- Throws:
DbxException- if an error occurs reading the response or response bodyIOException- if an error occurs writing the response body to the output stream.
-