public < E extends Throwable > long chunkedUploadAppend ( String uploadId , long uploadOffset , long chunkSize , DbxStreamWriter < E > writer ) throws DbxException , E { if ( uploadId == null ) throw new IllegalArgumentException ( "'uploadId' can't be null" ) ; if ( uploadId . length ( ) == 0 ) throw new IllegalArgumentException ( "'uploadId' can't be empty" ) ; if ( uploadOffset < 0 ) throw new IllegalArgumentException ( "'offset' can't be negative" ) ; String [ ] params = { "upload_id" , uploadId , "offset" , Long . toString ( uploadOffset ) , } ; HttpRequestor . Response response = chunkedUploadCommon ( params , chunkSize , writer ) ; String requestId = DbxRequestUtil . getRequestId ( response ) ; try { ChunkedUploadState correctedState = chunkedUploadCheckForOffsetCorrection ( response ) ; long expectedOffset = uploadOffset + chunkSize ; if ( correctedState != null ) { if ( ! correctedState . uploadId . equals ( uploadId ) ) { throw new BadResponseException ( requestId , "uploadId mismatch: us=" + jq ( uploadId ) + ", server=" + jq ( correctedState . uploadId ) ) ; } if ( correctedState . offset == uploadOffset ) { throw new BadResponseException ( requestId , "Corrected offset is same as given: " + uploadOffset ) ; } if ( correctedState . offset < uploadOffset ) { // Somehow the server lost track of the previous data we sent it. throw new BadResponseException ( requestId , "we were at offset " + uploadOffset + ", server said " + correctedState . offset ) ; } if ( correctedState . offset > expectedOffset ) { // Somehow the server has more data than we gave it! throw new BadResponseException ( requestId , "we were at offset " + uploadOffset + ", server said " + correctedState . offset ) ; } // Make sure the returned offset is within what we expect. assert correctedState . offset != expectedOffset ; return correctedState . offset ; } if ( response . getStatusCode ( ) != 200 ) throw DbxRequestUtil . unexpectedStatus ( response ) ; ChunkedUploadState returnedState = chunkedUploadParse200 ( response ) ; if ( returnedState . offset != expectedOffset ) { throw new BadResponseException ( requestId , "Expected offset " + expectedOffset + " bytes, but returned offset is " + returnedState . offset ) ; } return - 1 ; } finally { IOUtil . closeInput ( response . getBody ( ) ) ; } }
Append a chunk of data to a chunked upload session .