|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dropbox.client2.DropboxAPI.ChunkedUploader
public class DropboxAPI.ChunkedUploader
Represents a single chunked upload in progress. Uploads bytes from the given InputStream to dropbox using the chunked upload protocol. Completion of the upload can be detected by comparing the ChunkedUploader's offset against the expected size of the file being uploaded. Expected use:
DropboxAPI api = ... File bigFile = new File("99mb.avi"); FileInputStream in = new FileInputStream(bigFile); try { DropboxAPI.ChunkedUploader uploader = api.getChunkedUploader(in, bigFile.length()); int retryCounter = 0; while(!uploader.isComplete()) { try { uploader.upload(); } catch (DropboxException e) { if (retryCounter > MAX_RETRIES) break; // Give up after a while. retryCounter++; // Maybe wait a few seconds before retrying? } } } finally { in.close(); }
Method Summary | |
---|---|
void |
abort()
Aborts this chunked upload if it was already in progress. |
DropboxAPI.Entry |
finish(java.lang.String path,
java.lang.String parentRev)
Completes a chunked upload, commiting the already uploaded file to Dropbox. |
boolean |
getActive()
Whether or not this ChunkedUploader is active and has not yet been aborted. |
long |
getOffset()
Returns the last-known byte offset that the server expects to receive. |
boolean |
isComplete()
Whether or not this ChunkedUploader has completed its upload. |
void |
upload()
Convenience wrapper around upload(ProgressListener)
defaulting to a chunk size of 4 megabytes and no progress listener. |
void |
upload(ProgressListener listener)
Uploads multiple chunks of data to the server until the upload is complete or an error occurs. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public long getOffset()
public boolean isComplete()
public boolean getActive()
isComplete()
.
public void abort()
public void upload() throws DropboxException, java.io.IOException
upload(ProgressListener)
defaulting to a chunk size of 4 megabytes and no progress listener.
DropboxException
- If there was a transmission error
java.io.IOException
- If there was a problem reading from the given InputStream.
DropboxPartialFileException
- if the request was canceled before completion.public void upload(ProgressListener listener) throws DropboxException, java.io.IOException
listener
- A ProgressListener (can be null
) that will be notified of upload
progress. The progress notifications will be for the entire file.
DropboxException
- If there was a transmission error
java.io.IOException
- If there was a problem reading from the given InputStream.
DropboxPartialFileException
- if the request was canceled before completion.public DropboxAPI.Entry finish(java.lang.String path, java.lang.String parentRev) throws DropboxException
path
- the full Dropbox path where to put the file, including
directories and filename.parentRev
- the rev of the file at which the user started editing
it (obtained from a metadata call), or null if this is a new
upload. If null, or if it does not match the latest rev on the
server, a copy of the file will be created and you'll receive
the new metadata upon executing the request.
DropboxException
- if anything goes wrong.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |