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 java.lang.Object
implements java.io.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,
java.lang.String userId) |
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.
|
java.io.OutputStream |
getOutputStream()
Returns an
OutputStream that writes to the request body. |
protected abstract X |
newException(DbxWrappedException error) |
R |
uploadAndFinish(java.io.InputStream in)
Uploads all bytes read from the given
InputStream and returns the response. |
R |
uploadAndFinish(java.io.InputStream in,
IOUtil.ProgressListener progressListener)
This method is the same as
uploadAndFinish(InputStream, long) except for it allow
tracking the upload progress. |
R |
uploadAndFinish(java.io.InputStream in,
long limit)
Uploads up to
limit bytes read from the given InputStream and returns the
response. |
R |
uploadAndFinish(java.io.InputStream in,
long limit,
IOUtil.ProgressListener progressListener)
This method is the same as
uploadAndFinish(InputStream, long) except for it allows
tracking the upload progress. |
protected DbxUploader(HttpRequestor.Uploader httpUploader, StoneSerializer<R> responseSerializer, StoneSerializer<E> errorSerializer, java.lang.String userId)
protected abstract X newException(DbxWrappedException error)
public R uploadAndFinish(java.io.InputStream in) throws X extends DbxApiException, DbxException, java.io.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 responsejava.io.IOException
- if an error occurs reading the input stream.java.lang.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException
public R uploadAndFinish(java.io.InputStream in, IOUtil.ProgressListener progressListener) throws X extends DbxApiException, DbxException, java.io.IOException
uploadAndFinish(InputStream, long)
except for it allow
tracking the upload progress.in
- InputStream
containing data to uploadprogressListener
- OUtil.ProgressListener
to track the upload progress.
Only support OKHttpRequester and StandardHttpRequester.X
- if the server sent an error response for the requestDbxException
- if an error occurs uploading the data or reading the responsejava.io.IOException
- if an error occurs reading the input stream.java.lang.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException
public R uploadAndFinish(java.io.InputStream in, long limit) throws X extends DbxApiException, DbxException, java.io.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 responsejava.io.IOException
- if an error occurs reading the input stream.java.lang.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException
public R uploadAndFinish(java.io.InputStream in, long limit, IOUtil.ProgressListener progressListener) throws X extends DbxApiException, DbxException, java.io.IOException
uploadAndFinish(InputStream, long)
except for it allows
tracking the upload progress.in
- InputStream
containing data to uploadlimit
- Maximum number of bytes to read from the given InputStream
progressListener
- OUtil.ProgressListener
to track the upload progress.
Only support OKHttpRequester and StandardHttpRequester.X
- if the server sent an error response for the requestDbxException
- if an error occurs uploading the data or reading the responsejava.io.IOException
- if an error occurs reading the input stream.java.lang.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 java.io.Closeable
close
in interface java.lang.AutoCloseable
public void abort()
public java.io.OutputStream getOutputStream()
OutputStream
that writes to the request body. Remember to call finish()
to complete the request and retrieve the response.
Data written to this stream will be uploaded.
Typically you will not need this method and can use the more convenient uploadAndFinish(InputStream)
.java.lang.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 responsejava.lang.IllegalStateException
- if this uploader has already been closed (see close()
) or finished (see finish()
)X extends DbxApiException