public class DbxDownloader<R> extends Object implements 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,
InputStream body) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this downloader and releases its underlying resources.
|
R |
download(OutputStream out)
Downloads the response body to the given
OutputStream and returns the server
response. |
InputStream |
getInputStream()
Returns the
InputStream containing the response body bytes. |
R |
getResult()
Returns the server response.
|
public DbxDownloader(R result, InputStream body)
public R getResult()
public InputStream getInputStream()
InputStream
containing the response body bytes. Remember to call close()
after reading the stream to properly free up resources.IllegalStateException
- if this downloader has already been closed (see close()
)download(OutputStream)
public R download(OutputStream out) throws DbxException, 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 bodyIOException
- if an error occurs writing the response body to the output stream.IllegalStateException
- if this downloader has already been closed (see close()
)public void close()
getInputStream
will fail.close
in interface Closeable
close
in interface AutoCloseable