Class DbxDownloadStyleBuilder<R>

java.lang.Object
com.dropbox.core.v2.DbxDownloadStyleBuilder<R>
Type Parameters:
R - The return type of the DbxDownloader
Direct Known Subclasses:
DbxAppGetSharedLinkFileBuilder, DbxAppGetThumbnailV2Builder, DbxUserGetSharedLinkFileBuilder, DbxUserGetThumbnailV2Builder, DocsDownloadBuilder, DownloadBuilder, DownloadZipBuilder, ExportBuilder, GetPhotoBuilder, GetPreviewBuilder, GetThumbnailBuilder

public abstract class DbxDownloadStyleBuilder<R> extends Object
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 Details

    • DbxDownloadStyleBuilder

      protected DbxDownloadStyleBuilder()
  • Method Details

    • getHeaders

      protected List<HttpRequestor.Header> getHeaders()
    • start

      public abstract DbxDownloader<R> start() throws DbxException
      Issues the download request using this builder's request parameters and returns a DbxDownloader for reading the response body. Callers should fully read the response body using DbxDownloader.getInputStream() and close the downloader afterwards (see DbxDownloader.close()). This will allow for proper resource deallocation and connection re-use.. See download(java.io.OutputStream) convenience method for a simpler way to complete the request.
      Returns:
      DbxDownloader used to download data and read the response.
      Throws:
      DbxException - if an error occursing issuing the request
    • range

      public DbxDownloadStyleBuilder<R> range(long start, long length)
      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. If start is greater than the length of the content, the range request will be ignored and server will return the entire contents. If length extends beyond the end of the cont`ent, the server will return all bytes from start until the end of the content.
      Parameters:
      start - index of first byte in range (index starts at 0)
      length - number of bytes to download starting at start
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if start or length are negative
    • range

      public DbxDownloadStyleBuilder<R> range(long start)
      Sets the partial byte range to download. Only bytes from start (inclusive) until the end of the content will be downloaded. The HTTP Range header will be set for this request. If start is 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 - if start is negative
    • download

      public R download(OutputStream out) throws DbxException, IOException
      Convenience method for DbxDownloader.download(OutputStream):
      
          builder.start().download(out);
       
      Parameters:
      out - OutputStream to write response body to
      Returns:
      Response from server
      Throws:
      DbxException - if an error occurs reading the response or response body
      IOException - if an error occurs writing the response body to the output stream.