Search in sources :

Example 1 with BytecountStreamListener

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));
}
Also used : BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) HashMap(java.util.HashMap) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) File(ch.cyberduck.core.box.io.swagger.client.model.File) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener)

Example 2 with BytecountStreamListener

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));
}
Also used : BackgroundExceptionCallable(ch.cyberduck.core.threading.BackgroundExceptionCallable) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener)

Example 3 with BytecountStreamListener

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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) FileEntity(ch.cyberduck.core.brick.io.swagger.client.model.FileEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with BytecountStreamListener

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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) BufferWriteFeature(ch.cyberduck.core.shared.BufferWriteFeature) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with BytecountStreamListener

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) BoxWriteFeature(ch.cyberduck.core.box.BoxWriteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) BoxDeleteFeature(ch.cyberduck.core.box.BoxDeleteFeature) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BoxReadFeature(ch.cyberduck.core.box.BoxReadFeature) RandomNonceGenerator(ch.cyberduck.core.cryptomator.random.RandomNonceGenerator) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) BoxFindFeature(ch.cyberduck.core.box.BoxFindFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) BoxDirectoryFeature(ch.cyberduck.core.box.BoxDirectoryFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) BoxFileidProvider(ch.cyberduck.core.box.BoxFileidProvider) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbtractBoxTest(ch.cyberduck.core.box.AbtractBoxTest)

Aggregations

BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)89 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)86 Test (org.junit.Test)82 Path (ch.cyberduck.core.Path)75 IntegrationTest (ch.cyberduck.test.IntegrationTest)75 Delete (ch.cyberduck.core.features.Delete)72 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)71 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)62 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)62 Local (ch.cyberduck.core.Local)46 InputStream (java.io.InputStream)44 StreamCopier (ch.cyberduck.core.io.StreamCopier)41 BandwidthThrottle (ch.cyberduck.core.io.BandwidthThrottle)39 ByteArrayInputStream (java.io.ByteArrayInputStream)32 PathAttributes (ch.cyberduck.core.PathAttributes)20 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)16 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)16 CryptoReadFeature (ch.cyberduck.core.cryptomator.features.CryptoReadFeature)16