@Test public void testUploadSinglePartEuCentral() throws Exception { final S3ThresholdUploadService service = new S3ThresholdUploadService(session, 5 * 1024L ); final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final String name = UUID.randomUUID().toString(); final Path test = new Path(container, name, EnumSet.of(Path.Type.file)); final Local local = new Local(System.getProperty("java.io.tmpdir"), name); final String random = new RandomStringGenerator.Builder().build().generate(1000); IOUtils.write(random, local.getOutputStream(false), Charset.defaultCharset()); final TransferStatus status = new TransferStatus(); status.setLength((long) random.getBytes().length); status.setMime("text/plain"); status.setStorageClass(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY); service.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledLoginCallback()); assertEquals((long) random.getBytes().length, status.getOffset(), 0L); assertTrue(status.isComplete()); assertTrue(new S3FindFeature(session).find(test)); final PathAttributes attributes = new S3AttributesFinderFeature(session).find(test); assertEquals(random.getBytes().length, attributes.getSize()); assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, new S3StorageClassFeature(session).getClass(test)); final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(test); assertFalse(metadata.isEmpty()); assertEquals("text/plain", metadata.get("Content-Type")); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); }
@Override public StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback prompt) throws BackgroundException { if(status.getLength() >= threshold) { if(!preferences.getBoolean("s3.upload.multipart")) { log.warn("Multipart upload is disabled with property s3.upload.multipart"); if(status.getLength() < preferences.getLong("s3.upload.multipart.required.threshold")) { return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } } try { return new S3MultipartUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } catch(NotfoundException | InteroperabilityException e) { log.warn(String.format("Failure using multipart upload %s. Fallback to single upload.", e.getMessage())); } } return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); }
S3ThresholdUploadService implements Upload<StorageObject> { @Override public StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback prompt) throws BackgroundException { if(status.getLength() >= threshold) { if(!preferences.getBoolean("s3.upload.multipart")) { log.warn("Multipart upload is disabled with property s3.upload.multipart"); if(status.getLength() < preferences.getLong("s3.upload.multipart.required.threshold")) { return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } } try { return new S3MultipartUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } catch(NotfoundException | InteroperabilityException e) { log.warn(String.format("Failure using multipart upload %s. Fallback to single upload.", e.getMessage())); } } return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } }
S3ThresholdUploadService implements Upload<StorageObject> { @Override public StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback prompt) throws BackgroundException { if(status.getLength() >= threshold) { if(!preferences.getBoolean("s3.upload.multipart")) { log.warn("Multipart upload is disabled with property s3.upload.multipart"); if(status.getLength() < preferences.getLong("s3.upload.multipart.required.threshold")) { return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } } try { return new S3MultipartUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } catch(NotfoundException | InteroperabilityException e) { log.warn(String.format("Failure using multipart upload %s. Fallback to single upload.", e.getMessage())); } } return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } S3ThresholdUploadService(final S3Session session);  S3ThresholdUploadService(final S3Session session, final Long threshold); }
S3ThresholdUploadService implements Upload<StorageObject> { @Override public StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback prompt) throws BackgroundException { if(status.getLength() >= threshold) { if(!preferences.getBoolean("s3.upload.multipart")) { log.warn("Multipart upload is disabled with property s3.upload.multipart"); if(status.getLength() < preferences.getLong("s3.upload.multipart.required.threshold")) { return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } } try { return new S3MultipartUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } catch(NotfoundException | InteroperabilityException e) { log.warn(String.format("Failure using multipart upload %s. Fallback to single upload.", e.getMessage())); } } return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } S3ThresholdUploadService(final S3Session session);  S3ThresholdUploadService(final S3Session session, final Long threshold); @Override Write.Append append(final Path file, final Long length, final Cache<Path> cache); @Override StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener,
                                final TransferStatus status, final ConnectionCallback prompt); @Override Upload<StorageObject> withWriter(final Write<StorageObject> writer); }
S3ThresholdUploadService implements Upload<StorageObject> { @Override public StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback prompt) throws BackgroundException { if(status.getLength() >= threshold) { if(!preferences.getBoolean("s3.upload.multipart")) { log.warn("Multipart upload is disabled with property s3.upload.multipart"); if(status.getLength() < preferences.getLong("s3.upload.multipart.required.threshold")) { return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } } try { return new S3MultipartUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } catch(NotfoundException | InteroperabilityException e) { log.warn(String.format("Failure using multipart upload %s. Fallback to single upload.", e.getMessage())); } } return new S3SingleUploadService(session, writer).upload(file, local, throttle, listener, status, prompt); } S3ThresholdUploadService(final S3Session session);  S3ThresholdUploadService(final S3Session session, final Long threshold); @Override Write.Append append(final Path file, final Long length, final Cache<Path> cache); @Override StorageObject upload(final Path file, Local local, final BandwidthThrottle throttle, final StreamListener listener,
                                final TransferStatus status, final ConnectionCallback prompt); @Override Upload<StorageObject> withWriter(final Write<StorageObject> writer);  }