@Test public void testCopy() throws Exception { final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes(); final TransferStatus status = new TransferStatus().length(content.length); status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status)); final OutputStream out = new S3WriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); test.attributes().setSize(content.length); final Path copy = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final S3MultipartCopyFeature feature = new S3MultipartCopyFeature(session, new S3AccessControlListFeature(session)); feature.copy(test, copy, status, new DisabledConnectionCallback()); assertTrue(new S3FindFeature(session).find(test)); assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize()); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertTrue(new S3FindFeature(session).find(copy)); assertEquals(content.length, new S3AttributesFinderFeature(session).find(copy).getSize()); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { final List<MultipartPart> completed = new ArrayList<MultipartPart>(); final MultipartUpload multipart = session.getClient().multipartStartUpload( destination.getBucketName(), destination); if(log.isDebugEnabled()) { log.debug(String.format("Multipart upload started for %s with ID %s", multipart.getObjectKey(), multipart.getUploadId())); } final long size = status.getLength(); long remaining = size; long offset = 0; final List<Future<MultipartPart>> parts = new ArrayList<Future<MultipartPart>>(); for(int partNumber = 1; remaining > 0; partNumber++) { final Long length = Math.min(Math.max((size / S3DefaultMultipartService.MAXIMUM_UPLOAD_PARTS), partsize), remaining); parts.add(this.submit(source, multipart, partNumber, offset, length)); remaining -= length; offset += length; } for(Future<MultipartPart> future : parts) { try { completed.add(future.get()); } catch(InterruptedException e) { log.error("Part upload failed with interrupt failure"); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { log.warn(String.format("Part upload failed with execution failure %s", e.getMessage())); if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new BackgroundException(e.getCause()); } } final MultipartCompleted complete = session.getClient().multipartCompleteUpload(multipart, completed); if(log.isDebugEnabled()) { log.debug(String.format("Completed multipart upload for %s with checksum %s", complete.getObjectKey(), complete.getEtag())); } return complete.getVersionId(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } finally { pool.shutdown(false); } }
S3MultipartCopyFeature extends S3CopyFeature { @Override protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { final List<MultipartPart> completed = new ArrayList<MultipartPart>(); final MultipartUpload multipart = session.getClient().multipartStartUpload( destination.getBucketName(), destination); if(log.isDebugEnabled()) { log.debug(String.format("Multipart upload started for %s with ID %s", multipart.getObjectKey(), multipart.getUploadId())); } final long size = status.getLength(); long remaining = size; long offset = 0; final List<Future<MultipartPart>> parts = new ArrayList<Future<MultipartPart>>(); for(int partNumber = 1; remaining > 0; partNumber++) { final Long length = Math.min(Math.max((size / S3DefaultMultipartService.MAXIMUM_UPLOAD_PARTS), partsize), remaining); parts.add(this.submit(source, multipart, partNumber, offset, length)); remaining -= length; offset += length; } for(Future<MultipartPart> future : parts) { try { completed.add(future.get()); } catch(InterruptedException e) { log.error("Part upload failed with interrupt failure"); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { log.warn(String.format("Part upload failed with execution failure %s", e.getMessage())); if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new BackgroundException(e.getCause()); } } final MultipartCompleted complete = session.getClient().multipartCompleteUpload(multipart, completed); if(log.isDebugEnabled()) { log.debug(String.format("Completed multipart upload for %s with checksum %s", complete.getObjectKey(), complete.getEtag())); } return complete.getVersionId(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } finally { pool.shutdown(false); } } }
S3MultipartCopyFeature extends S3CopyFeature { @Override protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { final List<MultipartPart> completed = new ArrayList<MultipartPart>(); final MultipartUpload multipart = session.getClient().multipartStartUpload( destination.getBucketName(), destination); if(log.isDebugEnabled()) { log.debug(String.format("Multipart upload started for %s with ID %s", multipart.getObjectKey(), multipart.getUploadId())); } final long size = status.getLength(); long remaining = size; long offset = 0; final List<Future<MultipartPart>> parts = new ArrayList<Future<MultipartPart>>(); for(int partNumber = 1; remaining > 0; partNumber++) { final Long length = Math.min(Math.max((size / S3DefaultMultipartService.MAXIMUM_UPLOAD_PARTS), partsize), remaining); parts.add(this.submit(source, multipart, partNumber, offset, length)); remaining -= length; offset += length; } for(Future<MultipartPart> future : parts) { try { completed.add(future.get()); } catch(InterruptedException e) { log.error("Part upload failed with interrupt failure"); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { log.warn(String.format("Part upload failed with execution failure %s", e.getMessage())); if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new BackgroundException(e.getCause()); } } final MultipartCompleted complete = session.getClient().multipartCompleteUpload(multipart, completed); if(log.isDebugEnabled()) { log.debug(String.format("Completed multipart upload for %s with checksum %s", complete.getObjectKey(), complete.getEtag())); } return complete.getVersionId(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } finally { pool.shutdown(false); } } S3MultipartCopyFeature(final S3Session session);  S3MultipartCopyFeature(final S3Session session, final S3AccessControlListFeature acl); }
S3MultipartCopyFeature extends S3CopyFeature { @Override protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { final List<MultipartPart> completed = new ArrayList<MultipartPart>(); final MultipartUpload multipart = session.getClient().multipartStartUpload( destination.getBucketName(), destination); if(log.isDebugEnabled()) { log.debug(String.format("Multipart upload started for %s with ID %s", multipart.getObjectKey(), multipart.getUploadId())); } final long size = status.getLength(); long remaining = size; long offset = 0; final List<Future<MultipartPart>> parts = new ArrayList<Future<MultipartPart>>(); for(int partNumber = 1; remaining > 0; partNumber++) { final Long length = Math.min(Math.max((size / S3DefaultMultipartService.MAXIMUM_UPLOAD_PARTS), partsize), remaining); parts.add(this.submit(source, multipart, partNumber, offset, length)); remaining -= length; offset += length; } for(Future<MultipartPart> future : parts) { try { completed.add(future.get()); } catch(InterruptedException e) { log.error("Part upload failed with interrupt failure"); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { log.warn(String.format("Part upload failed with execution failure %s", e.getMessage())); if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new BackgroundException(e.getCause()); } } final MultipartCompleted complete = session.getClient().multipartCompleteUpload(multipart, completed); if(log.isDebugEnabled()) { log.debug(String.format("Completed multipart upload for %s with checksum %s", complete.getObjectKey(), complete.getEtag())); } return complete.getVersionId(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } finally { pool.shutdown(false); } } S3MultipartCopyFeature(final S3Session session);  S3MultipartCopyFeature(final S3Session session, final S3AccessControlListFeature acl);  }
S3MultipartCopyFeature extends S3CopyFeature { @Override protected String copy(final Path source, final S3Object destination, final TransferStatus status) throws BackgroundException { try { final List<MultipartPart> completed = new ArrayList<MultipartPart>(); final MultipartUpload multipart = session.getClient().multipartStartUpload( destination.getBucketName(), destination); if(log.isDebugEnabled()) { log.debug(String.format("Multipart upload started for %s with ID %s", multipart.getObjectKey(), multipart.getUploadId())); } final long size = status.getLength(); long remaining = size; long offset = 0; final List<Future<MultipartPart>> parts = new ArrayList<Future<MultipartPart>>(); for(int partNumber = 1; remaining > 0; partNumber++) { final Long length = Math.min(Math.max((size / S3DefaultMultipartService.MAXIMUM_UPLOAD_PARTS), partsize), remaining); parts.add(this.submit(source, multipart, partNumber, offset, length)); remaining -= length; offset += length; } for(Future<MultipartPart> future : parts) { try { completed.add(future.get()); } catch(InterruptedException e) { log.error("Part upload failed with interrupt failure"); throw new ConnectionCanceledException(e); } catch(ExecutionException e) { log.warn(String.format("Part upload failed with execution failure %s", e.getMessage())); if(e.getCause() instanceof BackgroundException) { throw (BackgroundException) e.getCause(); } throw new BackgroundException(e.getCause()); } } final MultipartCompleted complete = session.getClient().multipartCompleteUpload(multipart, completed); if(log.isDebugEnabled()) { log.debug(String.format("Completed multipart upload for %s with checksum %s", complete.getObjectKey(), complete.getEtag())); } return complete.getVersionId(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Cannot copy {0}", e, source); } finally { pool.shutdown(false); } } S3MultipartCopyFeature(final S3Session session);  S3MultipartCopyFeature(final S3Session session, final S3AccessControlListFeature acl);   }