public class DbxDownloader<R>
extends java.lang.Object
implements java.io.Closeable
FileOutputStream out = new FileOutputStream("test.txt");
try {
response = downloader.download(out);
} finally {
out.close();
}
Example using 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 and Description |
---|
DbxDownloader(R result,
java.io.InputStream body) |
DbxDownloader(R result,
java.io.InputStream body,
java.lang.String contentType) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this downloader and releases its underlying resources.
|
R |
download(java.io.OutputStream out)
Downloads the response body to the given
OutputStream and returns the server
response. |
R |
download(java.io.OutputStream out,
IOUtil.ProgressListener progressListener)
This method is the same as
download(OutputStream) except for allowing to track
download progress. |
java.lang.String |
getContentType()
Returns the value of the content-type header field.
|
java.io.InputStream |
getInputStream()
Returns the
InputStream containing the response body bytes. |
R |
getResult()
Returns the server response.
|
public DbxDownloader(R result, java.io.InputStream body, java.lang.String contentType)
public DbxDownloader(R result, java.io.InputStream body)
public R getResult()
public java.lang.String getContentType()
public java.io.InputStream getInputStream()
InputStream
containing the response body bytes. Remember to call close()
after reading the stream to properly free up resources.java.lang.IllegalStateException
- if this downloader has already been closed (see close()
)download(OutputStream)
public R download(java.io.OutputStream out) throws DbxException, java.io.IOException
OutputStream
and returns the server
response.
This method manages closing this downloader's resources, so no further calls to close()
are necessary. The underlying InputStream
returned by getInputStream()
will be closed by this method.
This method is the equivalent of
try {
InputStream in = downloader.getInputStream();
// read from in, write to out
return downloader.getResult();
} finally {
downloader.close();
}
out
- OutputStream
to write response body toDbxException
- if an error occurs reading the response or response bodyjava.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()
)public R download(java.io.OutputStream out, IOUtil.ProgressListener progressListener) throws DbxException, java.io.IOException
download(OutputStream)
except for allowing to track
download progress.out
- OutputStream
to write response body toprogressListener
- IOUtil.ProgressListener
to track the download progress.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.public void close()
getInputStream
will fail.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable