Example usage for com.amazonaws.services.s3 AmazonS3 copyPart

List of usage examples for com.amazonaws.services.s3 AmazonS3 copyPart

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3 copyPart.

Prototype

public CopyPartResult copyPart(CopyPartRequest copyPartRequest)
        throws SdkClientException, AmazonServiceException;

Source Link

Document

Copies a source object to a part of a multipart upload.

Usage

From source file:com.upplication.s3fs.AmazonS3Client.java

License:Open Source License

static CopyPartResult copyPart0(AmazonS3 client, CopyPartRequest request, S3MultipartOptions opts)
        throws IOException, InterruptedException {

    final String objectId = request.getUploadId();
    final int partNumber = request.getPartNumber();
    final long len = request.getLastByte() - request.getFirstByte();

    int attempt = 0;
    CopyPartResult result = null;/* w  w  w . j a  va  2 s .c  o  m*/
    while (result == null) {
        attempt++;
        try {
            log.trace("Copying multipart {} with length {} attempt {} for {} ", partNumber, len, attempt,
                    objectId);
            result = client.copyPart(request);
        } catch (AmazonClientException e) {
            if (attempt >= opts.getMaxAttempts())
                throw new IOException("Failed to upload multipart data to Amazon S3", e);

            log.debug("Failed to upload part {} attempt {} for {} -- Caused by: {}", partNumber, attempt,
                    objectId, e.getMessage());
            Thread.sleep(opts.getRetrySleepWithAttempt(attempt));
        }
    }

    return result;
}