use of ch.cyberduck.core.BytecountStreamListener in project cyberduck by iterate-ch.
the class BoxLargeUploadService method submit.
private Future<File> submit(final ThreadPool pool, final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus overall, final String uploadSessionId, final int partNumber, final long offset, final long length, final ConnectionCallback callback) {
if (log.isInfoEnabled()) {
log.info(String.format("Submit %s to queue with offset %d and length %d", file, offset, length));
}
final BytecountStreamListener counter = new BytecountStreamListener(listener);
return pool.execute(new SegmentRetryCallable<>(session.getHost(), new BackgroundExceptionCallable<File>() {
@Override
public File call() throws BackgroundException {
overall.validate();
final TransferStatus status = new TransferStatus().segment(true).withOffset(offset).withLength(length);
status.setPart(partNumber);
status.setHeader(overall.getHeader());
status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status));
final Map<String, String> parameters = new HashMap<>();
parameters.put(UPLOAD_SESSION_ID, uploadSessionId);
parameters.put(OVERALL_LENGTH, String.valueOf(overall.getLength()));
status.withParameters(parameters);
final File response = BoxLargeUploadService.this.upload(file, local, throttle, listener, status, overall, status, callback);
if (log.isInfoEnabled()) {
log.info(String.format("Received response %s for part %d", response, partNumber));
}
return response;
}
}, overall, counter));
}
use of ch.cyberduck.core.BytecountStreamListener in project cyberduck by iterate-ch.
the class BrickUploadFeature method submit.
private Future<TransferStatus> submit(final ThreadPool pool, final Path file, final Local local, final BandwidthThrottle throttle, final StreamListener listener, final TransferStatus overall, final String url, final Integer partNumber, final long offset, final long length, final ConnectionCallback callback) {
if (log.isInfoEnabled()) {
log.info(String.format("Submit part %d of %s to queue with offset %d and length %d", partNumber, file, offset, length));
}
final BytecountStreamListener counter = new BytecountStreamListener(listener);
return pool.execute(new SegmentRetryCallable<>(session.getHost(), new BackgroundExceptionCallable<TransferStatus>() {
@Override
public TransferStatus call() throws BackgroundException {
overall.validate();
final TransferStatus status = new TransferStatus().segment(true).withLength(length).withOffset(offset);
status.setChecksum(writer.checksum(file, status).compute(local.getInputStream(), status));
status.setUrl(url);
status.setPart(partNumber);
status.setHeader(overall.getHeader());
BrickUploadFeature.super.upload(file, local, throttle, listener, status, overall, status, callback);
if (log.isInfoEnabled()) {
log.info(String.format("Received response for part number %d", partNumber));
}
return status;
}
}, overall, counter));
}
use of ch.cyberduck.core.BytecountStreamListener in project cyberduck by iterate-ch.
the class BrickMultipartWriteFeatureTest method testWriteSinglePart.
@Test
public void testWriteSinglePart() throws Exception {
final BrickMultipartWriteFeature feature = new BrickMultipartWriteFeature(session, 5 * 1024 * 1024);
final Path container = new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume));
final TransferStatus status = new TransferStatus();
status.setLength(-1L);
final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final HttpResponseOutputStream<FileEntity> out = feature.write(file, status, new DisabledConnectionCallback());
final byte[] content = RandomUtils.nextBytes(4 * 1024 * 1024);
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final TransferStatus progress = new TransferStatus();
final BytecountStreamListener count = new BytecountStreamListener();
new StreamCopier(new TransferStatus(), progress).withListener(count).transfer(in, out);
assertEquals(content.length, count.getSent());
in.close();
out.close();
assertNull(out.getStatus());
assertTrue(new BrickFindFeature(session).find(file));
final PathAttributes attributes = new BrickAttributesFinderFeature(session).find(file);
assertEquals(content.length, attributes.getSize());
final byte[] compare = new byte[content.length];
final InputStream stream = new BrickReadFeature(session).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new BrickDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.BytecountStreamListener in project cyberduck by iterate-ch.
the class BufferWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final BufferWriteFeature feature = new BufferWriteFeature(session);
final byte[] content = RandomUtils.nextBytes(5 * 1024);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path file = new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final StatusOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final BytecountStreamListener count = new BytecountStreamListener();
new StreamCopier(status, status).withListener(count).transfer(in, out);
assertEquals(content.length, count.getSent());
assertEquals(content.length, status.getLength());
assertNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new BoxReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.BytecountStreamListener in project cyberduck by iterate-ch.
the class BoxWriteFeatureTest method testWriteVaultWithTimeStamp.
@Test
public void testWriteVaultWithTimeStamp() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final Path container = new BoxDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path vault = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final CryptoWriteFeature feature = new CryptoWriteFeature<>(session, new BoxWriteFeature(session, fileid), cryptomator);
final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setNonces(new RandomNonceGenerator());
writeStatus.setLength(-1L);
writeStatus.setTimestamp(Instant.now().getEpochSecond());
final StatusOutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final TransferStatus progress = new TransferStatus();
final BytecountStreamListener count = new BytecountStreamListener();
new StreamCopier(new TransferStatus(), progress).withListener(count).transfer(in, out);
assertEquals(content.length, count.getSent());
assertEquals(content.length, count.getRecv());
assertNotNull(out.getStatus());
assertTrue(new CryptoFindFeature(session, new BoxFindFeature(session, fileid), cryptomator).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new CryptoReadFeature(session, new BoxReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
cryptomator.getFeature(session, Delete.class, new BoxDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations