@Test public void testUploadMultipleFiles() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials( System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key") )); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Local local1 = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final TransferStatus status1; { final int length = 32770; final byte[] content = RandomUtils.nextBytes(length); final OutputStream out = local1.getOutputStream(false); IOUtils.write(content, out); out.close(); status1 = new TransferStatus().length(content.length); } final Local local2 = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final TransferStatus status2; { final int length = 32770; final byte[] content = RandomUtils.nextBytes(length); final OutputStream out = local2.getOutputStream(false); IOUtils.write(content, out); out.close(); status2 = new TransferStatus().length(content.length); } final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test1 = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Path test2 = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final SpectraBulkService bulk = new SpectraBulkService(session); final HashMap<TransferItem, TransferStatus> files = new HashMap<>(); files.put(new TransferItem(test1), status1); files.put(new TransferItem(test2), status2); bulk.pre(Transfer.Type.upload, files, new DisabledConnectionCallback()); final SpectraUploadFeature upload = new SpectraUploadFeature(new SpectraWriteFeature(session), new SpectraBulkService(session)); upload.upload(test1, local1, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status1, new DisabledConnectionCallback()); upload.upload(test2, local2, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status2, new DisabledConnectionCallback()); new SpectraDeleteFeature(session).delete(Arrays.asList(test1, test2), new DisabledLoginCallback(), new Delete.DisabledCallback()); local1.delete(); local2.delete(); session.close(); }
@Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } final List<TransferStatus> chunks = bulk.query(Transfer.Type.upload, file, status); StorageObject stored = null; for(TransferStatus chunk : chunks) { chunk.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), chunk)); stored = super.upload(file, local, throttle, listener, chunk, callback); } return stored; }
SpectraUploadFeature extends HttpUploadFeature<StorageObject, MessageDigest> { @Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } final List<TransferStatus> chunks = bulk.query(Transfer.Type.upload, file, status); StorageObject stored = null; for(TransferStatus chunk : chunks) { chunk.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), chunk)); stored = super.upload(file, local, throttle, listener, chunk, callback); } return stored; } }
SpectraUploadFeature extends HttpUploadFeature<StorageObject, MessageDigest> { @Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } final List<TransferStatus> chunks = bulk.query(Transfer.Type.upload, file, status); StorageObject stored = null; for(TransferStatus chunk : chunks) { chunk.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), chunk)); stored = super.upload(file, local, throttle, listener, chunk, callback); } return stored; } SpectraUploadFeature(final Write<StorageObject> writer, final SpectraBulkService bulk); }
SpectraUploadFeature extends HttpUploadFeature<StorageObject, MessageDigest> { @Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } final List<TransferStatus> chunks = bulk.query(Transfer.Type.upload, file, status); StorageObject stored = null; for(TransferStatus chunk : chunks) { chunk.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), chunk)); stored = super.upload(file, local, throttle, listener, chunk, callback); } return stored; } SpectraUploadFeature(final Write<StorageObject> writer, final SpectraBulkService bulk); @Override StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle,
                                final StreamListener listener, final TransferStatus status, final ConnectionCallback callback); @Override Upload<StorageObject> withWriter(final Write<StorageObject> writer); }
SpectraUploadFeature extends HttpUploadFeature<StorageObject, MessageDigest> { @Override public StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status)); } final List<TransferStatus> chunks = bulk.query(Transfer.Type.upload, file, status); StorageObject stored = null; for(TransferStatus chunk : chunks) { chunk.setChecksum(ChecksumComputeFactory.get(HashAlgorithm.md5).compute(local.getInputStream(), chunk)); stored = super.upload(file, local, throttle, listener, chunk, callback); } return stored; } SpectraUploadFeature(final Write<StorageObject> writer, final SpectraBulkService bulk); @Override StorageObject upload(final Path file, final Local local, final BandwidthThrottle throttle,
                                final StreamListener listener, final TransferStatus status, final ConnectionCallback callback); @Override Upload<StorageObject> withWriter(final Write<StorageObject> writer);  }