/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }
assertParameterNotNull(copyObjectRequest.getSourceKey(), "The source object key must be specified when a copy request is initiated."); assertParameterNotNull(copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getSourceKey() + " to " + copyObjectRequest.getDestinationBucketName() + "/" + copyObjectRequest.getDestinationKey(); copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey()) .withSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey()) .withRequesterPays(copyObjectRequest.isRequesterPays())
.withSourceKey(origReq.getSourceKey()) .withUploadId(uploadId) .withPartNumber(partNumber++)
@Override public CopyResult call() throws Exception { CompleteMultipartUploadResult res; try { CompleteMultipartUploadRequest req = new CompleteMultipartUploadRequest( origReq.getDestinationBucketName(), origReq.getDestinationKey(), uploadId, collectPartETags()) .withRequesterPays(origReq.isRequesterPays()) .withGeneralProgressListener(origReq.getGeneralProgressListener()) .withRequestMetricCollector(origReq.getRequestMetricCollector()) ; res = s3.completeMultipartUpload(req); } catch (Exception e) { monitor.reportFailure(); publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT); throw e; } CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(origReq.getSourceBucketName()); copyResult.setSourceKey(origReq.getSourceKey()); copyResult.setDestinationBucketName(res .getBucketName()); copyResult.setDestinationKey(res.getKey()); copyResult.setETag(res.getETag()); copyResult.setVersionId(res.getVersionId()); monitor.copyComplete(); return copyResult; }
String copySourceHeader = "/" + SdkHttpUtils.urlEncode(copyObjectRequest.getSourceBucketName(), true) + "/" + SdkHttpUtils.urlEncode(copyObjectRequest.getSourceKey(), true); if (copyObjectRequest.getSourceVersionId() != null) { copySourceHeader += "?versionId=" + copyObjectRequest.getSourceVersionId();
rejectNull(copyObjectRequest.getSourceBucketName(), "The source bucket name must be specified when copying an object"); rejectNull(copyObjectRequest.getSourceKey(), "The source object key must be specified when copying an object"); rejectNull(copyObjectRequest.getDestinationBucketName(),
/** * Constructs a copy part requests and returns it. * * @return Returns a new copy part request */ public synchronized CopyPartRequest getNextCopyPartRequest() { long partSize = Math.min(optimalPartSize, remainingBytes); CopyPartRequest request = new CopyPartRequest() .withSourceBucketName(copyObjectRequest.getSourceBucketName()) .withSourceKey(copyObjectRequest.getSourceKey()) .withUploadId(uploadId) .withPartNumber(partNumber++) .withDestinationBucketName( copyObjectRequest.getDestinationBucketName()) .withDestinationKey(copyObjectRequest.getDestinationKey()) .withSourceVersionId(copyObjectRequest.getSourceVersionId()) .withFirstByte(new Long(offset)) .withLastByte(new Long(offset + partSize - 1)) .withSourceSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey()) .withDestinationSSECustomerKey(copyObjectRequest.getDestinationSSECustomerKey()); setOtherMetadataInRequest(request); offset += partSize; remainingBytes -= partSize; return request; }
/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }
assertParameterNotNull(copyObjectRequest.getSourceKey(), "The source object key must be specified when a copy request is initiated."); assertParameterNotNull( + copyObjectRequest.getSourceKey() + " to " + copyObjectRequest.getDestinationBucketName() + "/" + copyObjectRequest.getDestinationKey(); new GetObjectMetadataRequest( copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey()) .withSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey());
/** * Completes the multipart upload and returns the result. */ private CopyResult completeMultipartUpload() { CompleteMultipartUploadResult completeMultipartUploadResult = s3 .completeMultipartUpload(new CompleteMultipartUploadRequest( copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey(), uploadId, collectPartETags())); copyComplete(); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(completeMultipartUploadResult .getBucketName()); copyResult.setDestinationKey(completeMultipartUploadResult.getKey()); copyResult.setETag(completeMultipartUploadResult.getETag()); copyResult.setVersionId(completeMultipartUploadResult.getVersionId()); return copyResult; }
private CopyObjectResult doCopyObject(CopyObjectRequest request) { try { return s3Client.copyObject(request); } catch (Exception e) { StringBuilder err = new StringBuilder("Error copying from: "); err.append(request.getSourceBucketName()); err.append(" / "); err.append(request.getSourceKey()); err.append(", to: "); err.append(request.getDestinationBucketName()); err.append(" / "); err.append(request.getDestinationKey()); log.error(err.toString() + "msg: {}", e.getMessage()); throw new StorageException(err.toString(), e, RETRY); } }
Request<? extends AmazonWebServiceRequest> request, CopyObjectRequest copyObjectRequest) { String copySourceHeader = "/" + copyObjectRequest.getSourceBucketName() + "/" + copyObjectRequest.getSourceKey();
assertParameterNotNull(copyObjectRequest.getSourceBucketName(), "The source bucket name must be specified when copying an object"); assertParameterNotNull(copyObjectRequest.getSourceKey(), "The source object key must be specified when copying an object"); assertParameterNotNull(copyObjectRequest.getDestinationBucketName(),
/** * Constructs a copy part requests and returns it. * * @return Returns a new copy part request */ public synchronized CopyPartRequest getNextCopyPartRequest() { long partSize = Math.min(optimalPartSize, remainingBytes); CopyPartRequest request = new CopyPartRequest() .withSourceBucketName(copyObjectRequest.getSourceBucketName()) .withSourceKey(copyObjectRequest.getSourceKey()) .withUploadId(uploadId) .withPartNumber(partNumber++) .withDestinationBucketName( copyObjectRequest.getDestinationBucketName()) .withDestinationKey(copyObjectRequest.getDestinationKey()) .withSourceVersionId(copyObjectRequest.getSourceVersionId()) .withFirstByte(new Long(offset)) .withLastByte(new Long(offset + partSize - 1)) .withSourceSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey()) .withDestinationSSECustomerKey(copyObjectRequest.getDestinationSSECustomerKey()); setOtherMetadataInRequest(request); offset += partSize; remainingBytes -= partSize; return request; }
/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }
/** * Performs the copy of the Amazon S3 object from source bucket to * destination bucket. The Amazon S3 object is copied to destination in one * single request. * * @returns CopyResult response information from the server. */ private CopyResult copyInOneChunk() { CopyObjectResult copyObjectResult = s3.copyObject(copyObjectRequest); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(copyObjectRequest .getDestinationBucketName()); copyResult.setDestinationKey(copyObjectRequest.getDestinationKey()); copyResult.setETag(copyObjectResult.getETag()); copyResult.setVersionId(copyObjectResult.getVersionId()); return copyResult; }
@Test public void testStoreExtractedText() throws BinaryStoreException { String extractedText = "text-that-has-been-extracted"; expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY)) .andReturn(new ObjectMetadata()); Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance(); expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null); replayAll(); BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT); s3BinaryStore.storeExtractedText(binaryValue, extractedText); CopyObjectRequest copyRequest = copyRequestCapture.getValue(); assertEquals(BUCKET, copyRequest.getSourceBucketName()); assertEquals(BUCKET, copyRequest.getDestinationBucketName()); assertEquals(TEST_KEY, copyRequest.getSourceKey()); assertEquals(TEST_KEY, copyRequest.getDestinationKey()); assertEquals(extractedText, copyRequest.getNewObjectMetadata() .getUserMetadata() .get(s3BinaryStore.EXTRACTED_TEXT_KEY)); }
@Test public void testStoreMimeType() throws BinaryStoreException { expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY)) .andReturn(new ObjectMetadata()); Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance(); expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null); replayAll(); BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT); s3BinaryStore.storeMimeType(binaryValue, TEST_MIME); CopyObjectRequest copyRequest = copyRequestCapture.getValue(); assertEquals(BUCKET, copyRequest.getSourceBucketName()); assertEquals(BUCKET, copyRequest.getDestinationBucketName()); assertEquals(TEST_KEY, copyRequest.getSourceKey()); assertEquals(TEST_KEY, copyRequest.getDestinationKey()); assertEquals(TEST_MIME, copyRequest.getNewObjectMetadata().getContentType()); }
/** * Completes the multipart upload and returns the result. */ private CopyResult completeMultipartUpload() { CompleteMultipartUploadResult completeMultipartUploadResult = s3 .completeMultipartUpload(new CompleteMultipartUploadRequest( copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey(), uploadId, collectPartETags())); copyComplete(); CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(copyObjectRequest.getSourceBucketName()); copyResult.setSourceKey(copyObjectRequest.getSourceKey()); copyResult.setDestinationBucketName(completeMultipartUploadResult .getBucketName()); copyResult.setDestinationKey(completeMultipartUploadResult.getKey()); copyResult.setETag(completeMultipartUploadResult.getETag()); copyResult.setVersionId(completeMultipartUploadResult.getVersionId()); return copyResult; }
@Override public CopyResult call() throws Exception { CompleteMultipartUploadResult res; try { CompleteMultipartUploadRequest req = new CompleteMultipartUploadRequest( origReq.getDestinationBucketName(), origReq.getDestinationKey(), uploadId, collectPartETags()) .withRequesterPays(origReq.isRequesterPays()) .withGeneralProgressListener(origReq.getGeneralProgressListener()) .withRequestMetricCollector(origReq.getRequestMetricCollector()) ; res = s3.completeMultipartUpload(req); } catch (Exception e) { publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT); throw e; } CopyResult copyResult = new CopyResult(); copyResult.setSourceBucketName(origReq.getSourceBucketName()); copyResult.setSourceKey(origReq.getSourceKey()); copyResult.setDestinationBucketName(res .getBucketName()); copyResult.setDestinationKey(res.getKey()); copyResult.setETag(res.getETag()); copyResult.setVersionId(res.getVersionId()); monitor.copyComplete(); return copyResult; }