Package com.dropbox.core
Class DbxDownloader<R>
- java.lang.Object
- 
- com.dropbox.core.DbxDownloader<R>
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable
 
 public class DbxDownloader<R> extends java.lang.Object implements java.io.CloseableClass for handling download requests. This class provides methods for downloading a request body and reading the server response. Example usage:
 Example usingFileOutputStream out = new FileOutputStream("test.txt"); try { response = downloader.download(out); } finally { out.close(); }getInputStream():FileOutputStream out = new FileOutputStream("test.txt"); response = downloader.getResult(); try { InputStream in = downloader.getInputStream(); // read from in, write to out } finally { downloader.close(); }
- 
- 
Constructor SummaryConstructors Constructor Description DbxDownloader(R result, java.io.InputStream body)DbxDownloader(R result, java.io.InputStream body, java.lang.String contentType)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this downloader and releases its underlying resources.Rdownload(java.io.OutputStream out)Downloads the response body to the givenOutputStreamand returns the server response.Rdownload(java.io.OutputStream out, IOUtil.ProgressListener progressListener)This method is the same asdownload(OutputStream)except for allowing to track download progress.java.lang.StringgetContentType()Returns the value of the content-type header field.java.io.InputStreamgetInputStream()Returns theInputStreamcontaining the response body bytes.RgetResult()Returns the server response.
 
- 
- 
- 
Method Detail- 
getResultpublic R getResult() Returns the server response. Returns the response from the server that is separate from the response body (data to be downloaded).- Returns:
- Response from server
 
 - 
getContentTypepublic java.lang.String getContentType() Returns the value of the content-type header field.- Returns:
- the content type, or null if not known.
 
 - 
getInputStreampublic java.io.InputStream getInputStream() Returns theInputStreamcontaining the response body bytes. Remember to callclose()after reading the stream to properly free up resources.- Returns:
- Response body input stream.
- Throws:
- java.lang.IllegalStateException- if this downloader has already been closed (see- close())
- See Also:
- download(OutputStream)
 
 - 
downloadpublic R download(java.io.OutputStream out) throws DbxException, java.io.IOException Downloads the response body to the givenOutputStreamand returns the server response. This method manages closing this downloader's resources, so no further calls toclose()are necessary. The underlyingInputStreamreturned bygetInputStream()will be closed by this method. This method is the equivalent oftry { InputStream in = downloader.getInputStream(); // read from in, write to out return downloader.getResult(); } finally { downloader.close(); }- Parameters:
- out-- OutputStreamto write response body to
- Returns:
- Response from server
- Throws:
- DbxException- if an error occurs reading the response or response body
- java.io.IOException- if an error occurs writing the response body to the output stream.
- java.lang.IllegalStateException- if this downloader has already been closed (see- close())
 
 - 
downloadpublic R download(java.io.OutputStream out, IOUtil.ProgressListener progressListener) throws DbxException, java.io.IOException This method is the same asdownload(OutputStream)except for allowing to track download progress.- Parameters:
- out-- OutputStreamto write response body to
- progressListener-- IOUtil.ProgressListenerto track the download progress.
- Returns:
- Response from server
- Throws:
- DbxException- if an error occurs reading the response or response body.
- java.io.IOException- if an error occurs writing the response body to the output stream.
 
 - 
closepublic void close() Closes this downloader and releases its underlying resources. After calling this method, calls togetInputStream()will fail.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
 
 
- 
 
-