R
- response type returned by server on request successX
- exception type returned by server on request failurepublic abstract class DbxUploader<R,E,X extends DbxApiException> extends Object implements Closeable
FileInputStream in = new FileInputStream("test.txt");
try {
response = uploader.uploadAndFinish(in);
} finally {
in.close();
}
Example using getOutputStream()
:
try {
OutputStream out = uploader.getOutputStream();
out.write(data);
response = uploader.finish();
} finally {
uploader.close();
}
Modifier | Constructor and Description |
---|---|
protected |
DbxUploader(HttpRequestor.Uploader httpUploader,
StoneSerializer<R> responseSerializer,
StoneSerializer<E> errorSerializer) |
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts this upload request and closes its underlying connection.
|
void |
close()
Closes this upload request and releases its underlying resources.
|
R |
finish()
Completes the request and returns response from the server.
|
OutputStream |
getOutputStream()
Returns an
OutputStream that writes to the request body. |
protected abstract X |
newException(DbxWrappedException error) |
R |
uploadAndFinish(InputStream in)
Uploads all bytes read from the given
InputStream and returns the response. |
R |
uploadAndFinish(InputStream in,
long limit)
Uploads up to
limit bytes read from the given InputStream and returns the
response. |
protected DbxUploader(HttpRequestor.Uploader httpUploader, StoneSerializer<R> responseSerializer, StoneSerializer<E> errorSerializer)
protected abstract X newException(DbxWrappedException error)
public R uploadAndFinish(InputStream in) throws X extends DbxApiException, DbxException, IOException
InputStream
and returns the response.
This method manages closing this uploader's resources, so no further calls to close()
are necessary. The underlying OutputStream
returned by getOutputStream()
will be closed by this method.
This method is the equivalent of
try {
OutputStream out = uploader.getOutputStream();
// read from in, write to out
response = uploader.finish();
} finally {
uploader.close();
}
in
- InputStream
containing data to uploadX
- if the server sent an error response for the requestDbxException
- if an error occurs uploading the data or reading the responseIOException
- if an error occurs reading the input stream.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException
public R uploadAndFinish(InputStream in, long limit) throws X extends DbxApiException, DbxException, IOException
limit
bytes read from the given InputStream
and returns the
response.
This method upload bytes from the given InputStream
until limit
bytes have
been read or end-of-stream is detected. Use uploadAndFinish(InputStream)
to upload the entire
stream.
This method manages closing this uploader's resources, so no further calls to close()
are necessary. The underlying OutputStream
returned by getOutputStream()
will be closed by this method.
This method is the equivalent of
try {
OutputStream out = uploader.getOutputStream();
// read at most `limit` bytes from in, write to out
response = uploader.finish();
} finally {
uploader.close();
}
in
- InputStream
containing data to uploadlimit
- Maximum number of bytes to read from the given InputStream
X
- if the server sent an error response for the requestDbxException
- if an error occurs uploading the data or reading the responseIOException
- if an error occurs reading the input stream.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException
public void close()
try {
OutputStream out = uploader.getOutputStream();
out.write(data);
response = uploader.finish();
} finally {
uploader.close();
}
close
in interface Closeable
close
in interface AutoCloseable
public void abort()
public OutputStream getOutputStream()
OutputStream
that writes to the request body. Remember to call finish()
to complete the request and retrieve the response.
Data writen to this stream will be uploaded.
Typically you will not need this method and can use the more convenient uploadAndFinish(InputStream)
.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)uploadAndFinish(InputStream)
public R finish() throws X extends DbxApiException, DbxException
OutputStream
(see
getOutputStream()
).X
- if the server sent an error response for the requestDbxException
- if an error occurs sending the upload or reading the responseIllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException