library/src/main/java/com/kdgregory/aws/utils/s3/MultipartUpload.java
/**
     *  Uploads a part from within a larger buffer. This will either dispatch a task to the
     *  threadpool or execute the upload inline.
     *  <p>
     *  Note: when using a threadpool, the provided buffer is copied, and may be modified
     *  by the caller while the task is outstanding. When executing inline, the buffer is
     *  not copied, and must not be modified by another thread until the part is uploaded.
     *
     *  @param data         Contains the part to upload.
     *  @param off          Offset of part within passed array.
     *  @param len          Length of part within passed array.
     *  @param isLastPart   If <code>true</code> signifies that this is the last part of
     *                      the upload.
     */
Uploads a part from within a larger buffer. This will either dispatch a task to the
threadpool or execute the upload inline.

Note: when using a threadpool, the provided buffer is copied, and may be modified
by the caller while the task is outstanding. When executing inline, the buffer is
not copied, and must not be modified by another thread until the part is uploaded.

@param data         Contains the part to upload.
@param off          Offset of part within passed array.
@param len          Length of part within passed array.
@param isLastPart   If true signifies that this is the last part of
the upload.
Uploads a part from within a larger buffer . This will either dispatch a task to the threadpool or execute the upload inline . Note : when using a threadpool the provided buffer is copied and may be modified by the caller while the task is outstanding . When executing inline the buffer is not copied and must not be modified by another thread until the part is uploaded . @param data Contains the part to upload . @param off Offset of part within passed array . @param len Length of part within passed array . @param isLastPart If true signifies that this is the last part of the upload .
public void uploadPart(byte[] data, int off, int len, boolean isLastPart)
    {
        final int localPartNumber = ++partNumber;
        ByteArrayInputStream dataStream;
        if (executor != null)
        {
            byte[] localBuf = new byte[len];
            System.arraycopy(data, off, localBuf, 0, len);
            dataStream = new ByteArrayInputStream(localBuf);
        }
        else
        {
            dataStream = new ByteArrayInputStream(data, off, len);
        }
        final UploadPartRequest request = new UploadPartRequest()
                                          .withBucketName(bucket)
                                          .withKey(key)
                                          .withUploadId(uploadId)
                                          .withPartNumber(localPartNumber)
                                          .withPartSize(len)
                                          .withInputStream(dataStream)
                                          .withLastPart(isLastPart);
        logger.debug("submitting part " + localPartNumber + " for s3://" + bucket + "/" + key);
        Callable<PartETag> callable = new Callable<PartETag>()
            {
                @Override
                public PartETag call() throws Exception
                {
                    logger.debug("uploading part " + localPartNumber + " for s3://" + bucket + "/" + key);
                    UploadPartResult response = client.uploadPart(request);
                    String etag = response.getETag();
                    logger.debug("completed part " + localPartNumber + " for s3://" + bucket + "/" + key + "; etag is " + etag);
                    return new PartETag(localPartNumber, etag);
                }
            };
        if (executor != null)
        {
            waitForTaskSlot();
            futures.add(executor.submit(callable));
        }
        else
        {
            Future<PartETag> future = executeInline(callable);
            unwrap(future);
            futures.add(future);
        }
    }
public void uploadPart ( byte [ ] data , int off , int len , boolean isLastPart ) { final int localPartNumber = ++ partNumber ; ByteArrayInputStream dataStream ; if ( executor != null ) { byte [ ] localBuf = new byte [ len ] ; System . arraycopy ( data , off , localBuf , 0 , len ) ; dataStream = new ByteArrayInputStream ( localBuf ) ; } else { dataStream = new ByteArrayInputStream ( data , off , len ) ; } final UploadPartRequest request = new UploadPartRequest ( ) . withBucketName ( bucket ) . withKey ( key ) . withUploadId ( uploadId ) . withPartNumber ( localPartNumber ) . withPartSize ( len ) . withInputStream ( dataStream ) . withLastPart ( isLastPart ) ; logger . debug ( "submitting part " + localPartNumber + " for s3://" + bucket + "/" + key ) ; Callable < PartETag > callable = new Callable < PartETag > ( ) { @ Override public PartETag call ( ) throws Exception { logger . debug ( "uploading part " + localPartNumber + " for s3://" + bucket + "/" + key ) ; UploadPartResult response = client . uploadPart ( request ) ; String etag = response . getETag ( ) ; logger . debug ( "completed part " + localPartNumber + " for s3://" + bucket + "/" + key + "; etag is " + etag ) ; return new PartETag ( localPartNumber , etag ) ; } } ; if ( executor != null ) { waitForTaskSlot ( ) ; futures . add ( executor . submit ( callable ) ) ; } else { Future < PartETag > future = executeInline ( callable ) ; unwrap ( future ) ; futures . add ( future ) ; } }
Uploads a part from within a larger buffer.
Uploads a part from within a larger buffer .
// we call <code>unwrap()</code> here in order to fail fast if there was an exception, //  but we also add the future to the list so that complete() doesn't need special code