Search in sources :

Example 1 with S3SingleUploadService

use of ch.cyberduck.core.s3.S3SingleUploadService in project cyberduck by iterate-ch.

the class S3SingleUploadServiceTest method testUploadVault.

@Test
public void testUploadVault() throws Exception {
    final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    final Path vault = new Path(home, 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 Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final int length = 5242880;
    final byte[] content = RandomUtils.nextBytes(length);
    IOUtils.write(content, local.getOutputStream(false));
    final TransferStatus writeStatus = new TransferStatus();
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    writeStatus.setLength(content.length);
    final BytecountStreamListener count = new BytecountStreamListener();
    final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3SingleUploadService(session, new S3WriteFeature(session)), new S3WriteFeature(session), cryptomator);
    m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), count, writeStatus, null);
    assertEquals(content.length, count.getSent());
    assertTrue(writeStatus.isComplete());
    assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final TransferStatus readStatus = new TransferStatus().withLength(content.length);
    final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
    new StreamCopier(readStatus, readStatus).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) 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) CryptoUploadFeature(ch.cyberduck.core.cryptomator.features.CryptoUploadFeature) Path(ch.cyberduck.core.Path) S3FindFeature(ch.cyberduck.core.s3.S3FindFeature) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) InputStream(java.io.InputStream) Local(ch.cyberduck.core.Local) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) S3SingleUploadService(ch.cyberduck.core.s3.S3SingleUploadService) S3ReadFeature(ch.cyberduck.core.s3.S3ReadFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)1 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)1 Local (ch.cyberduck.core.Local)1 Path (ch.cyberduck.core.Path)1 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)1 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)1 CryptoReadFeature (ch.cyberduck.core.cryptomator.features.CryptoReadFeature)1 CryptoUploadFeature (ch.cyberduck.core.cryptomator.features.CryptoUploadFeature)1 Delete (ch.cyberduck.core.features.Delete)1 BandwidthThrottle (ch.cyberduck.core.io.BandwidthThrottle)1 StreamCopier (ch.cyberduck.core.io.StreamCopier)1 AbstractS3Test (ch.cyberduck.core.s3.AbstractS3Test)1 S3AttributesFinderFeature (ch.cyberduck.core.s3.S3AttributesFinderFeature)1 S3DefaultDeleteFeature (ch.cyberduck.core.s3.S3DefaultDeleteFeature)1 S3FindFeature (ch.cyberduck.core.s3.S3FindFeature)1 S3ReadFeature (ch.cyberduck.core.s3.S3ReadFeature)1