List of usage examples for com.amazonaws.services.s3.model CopyPartResult getPartETag
public PartETag getPartETag()
From source file:org.apache.beam.sdk.io.aws.s3.S3FileSystem.java
License:Apache License
@VisibleForTesting
CompleteMultipartUploadResult multipartCopy(S3ResourceId sourcePath, S3ResourceId destinationPath,
ObjectMetadata sourceObjectMetadata) throws AmazonClientException {
InitiateMultipartUploadRequest initiateUploadRequest = new InitiateMultipartUploadRequest(
destinationPath.getBucket(), destinationPath.getKey()).withStorageClass(options.getS3StorageClass())
.withObjectMetadata(sourceObjectMetadata);
initiateUploadRequest.setSSECustomerKey(options.getSSECustomerKey());
InitiateMultipartUploadResult initiateUploadResult = amazonS3.get()
.initiateMultipartUpload(initiateUploadRequest);
final String uploadId = initiateUploadResult.getUploadId();
List<PartETag> eTags = new ArrayList<>();
final long objectSize = sourceObjectMetadata.getContentLength();
// extra validation in case a caller calls directly S3FileSystem.multipartCopy
// without using S3FileSystem.copy in the future
if (objectSize == 0) {
final CopyPartRequest copyPartRequest = new CopyPartRequest()
.withSourceBucketName(sourcePath.getBucket()).withSourceKey(sourcePath.getKey())
.withDestinationBucketName(destinationPath.getBucket())
.withDestinationKey(destinationPath.getKey()).withUploadId(uploadId).withPartNumber(1);
copyPartRequest.setSourceSSECustomerKey(options.getSSECustomerKey());
copyPartRequest.setDestinationSSECustomerKey(options.getSSECustomerKey());
CopyPartResult copyPartResult = amazonS3.get().copyPart(copyPartRequest);
eTags.add(copyPartResult.getPartETag());
} else {/* w ww . ja v a2 s. c om*/
long bytePosition = 0;
Integer uploadBufferSizeBytes = options.getS3UploadBufferSizeBytes();
// Amazon parts are 1-indexed, not zero-indexed.
for (int partNumber = 1; bytePosition < objectSize; partNumber++) {
final CopyPartRequest copyPartRequest = new CopyPartRequest()
.withSourceBucketName(sourcePath.getBucket()).withSourceKey(sourcePath.getKey())
.withDestinationBucketName(destinationPath.getBucket())
.withDestinationKey(destinationPath.getKey()).withUploadId(uploadId)
.withPartNumber(partNumber).withFirstByte(bytePosition)
.withLastByte(Math.min(objectSize - 1, bytePosition + uploadBufferSizeBytes - 1));
copyPartRequest.setSourceSSECustomerKey(options.getSSECustomerKey());
copyPartRequest.setDestinationSSECustomerKey(options.getSSECustomerKey());
CopyPartResult copyPartResult = amazonS3.get().copyPart(copyPartRequest);
eTags.add(copyPartResult.getPartETag());
bytePosition += uploadBufferSizeBytes;
}
}
CompleteMultipartUploadRequest completeUploadRequest = new CompleteMultipartUploadRequest()
.withBucketName(destinationPath.getBucket()).withKey(destinationPath.getKey())
.withUploadId(uploadId).withPartETags(eTags);
return amazonS3.get().completeMultipartUpload(completeUploadRequest);
}