Search in sources :

Example 1 with Local

use of ch.cyberduck.core.Local in project cyberduck by iterate-ch.

the class CryptoB2SingleTransferWorkerTest method testUpload.

@Test
public void testUpload() throws Exception {
    final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path dir1 = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
    final byte[] content = RandomUtils.nextBytes(62768);
    final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local localFile1 = new Local(localDirectory1, file1.getName());
    final OutputStream out1 = localFile1.getOutputStream(false);
    IOUtils.write(content, out1);
    out1.close();
    final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local localFile2 = new Local(localDirectory1, file2.getName());
    final OutputStream out2 = localFile2.getOutputStream(false);
    IOUtils.write(content, out2);
    out2.close();
    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 Transfer t = new UploadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(dir1, localDirectory1)), new NullFilter<>());
    assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
    }.run(session));
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    assertTrue(new CryptoFindFeature(session, new B2FindFeature(session, fileid), cryptomator).find(dir1));
    assertEquals(content.length, new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session, fileid), cryptomator).find(file1).getSize());
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
        assertArrayEquals(content, buffer.toByteArray());
    }
    assertEquals(content.length, new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session, fileid), cryptomator).find(file2).getSize());
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
        assertArrayEquals(content, buffer.toByteArray());
    }
    cryptomator.getFeature(session, Delete.class, new B2DeleteFeature(session, fileid)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    localFile1.delete();
    localFile2.delete();
    localDirectory1.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) TestProtocol(ch.cyberduck.core.TestProtocol) B2ReadFeature(ch.cyberduck.core.b2.B2ReadFeature) TransferAction(ch.cyberduck.core.transfer.TransferAction) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) B2VersionIdProvider(ch.cyberduck.core.b2.B2VersionIdProvider) B2AttributesFinderFeature(ch.cyberduck.core.b2.B2AttributesFinderFeature) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) B2DeleteFeature(ch.cyberduck.core.b2.B2DeleteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) InputStream(java.io.InputStream) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) B2FindFeature(ch.cyberduck.core.b2.B2FindFeature) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) TransferItem(ch.cyberduck.core.transfer.TransferItem) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractB2Test(ch.cyberduck.core.b2.AbstractB2Test) Test(org.junit.Test)

Example 2 with Local

use of ch.cyberduck.core.Local in project cyberduck by iterate-ch.

the class BrickDeleteFeatureTest method testDeleteWithLock.

@Test
public void testDeleteWithLock() throws Exception {
    final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), test.getName());
    final byte[] random = RandomUtils.nextBytes(2547);
    IOUtils.write(random, local.getOutputStream(false));
    final TransferStatus status = new TransferStatus().withLength(random.length);
    new BrickUploadFeature(session, new BrickWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledLoginCallback());
    local.delete();
    final String lock = new BrickLockFeature(session).lock(test);
    new BrickDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) Local(ch.cyberduck.core.Local) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with Local

use of ch.cyberduck.core.Local in project cyberduck by iterate-ch.

the class BrickReadFeatureTest method testReadRange.

@Test
public void testReadRange() throws Exception {
    final Path room = new BrickDirectoryFeature(session).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final Path test = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new BrickTouchFeature(session).touch(test, new TransferStatus());
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = RandomUtils.nextBytes(1023);
    final OutputStream out = local.getOutputStream(false);
    assertNotNull(out);
    IOUtils.write(content, out);
    out.close();
    final TransferStatus upload = new TransferStatus().withLength(content.length);
    upload.setExists(true);
    new BrickUploadFeature(session, new BrickWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), upload, new DisabledConnectionCallback());
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    status.setAppend(true);
    status.setOffset(100L);
    final InputStream in = new BrickReadFeature(session).read(test, status.withLength(content.length - 100), new DisabledConnectionCallback());
    assertNotNull(in);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
    new StreamCopier(status, status).transfer(in, buffer);
    final byte[] reference = new byte[content.length - 100];
    System.arraycopy(content, 100, reference, 0, content.length - 100);
    assertArrayEquals(reference, buffer.toByteArray());
    in.close();
    new BrickDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpResponseOutputStream(ch.cyberduck.core.http.HttpResponseOutputStream) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) 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 Local

use of ch.cyberduck.core.Local in project cyberduck by iterate-ch.

the class BrickCopyFeatureTest method testCopyToExistingFile.

@Test
public void testCopyToExistingFile() throws Exception {
    final Path folder = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    new BrickDirectoryFeature(session).mkdir(folder, new TransferStatus());
    final Path test = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), test.getName());
    final byte[] random = RandomUtils.nextBytes(2547);
    IOUtils.write(random, local.getOutputStream(false));
    final TransferStatus status = new TransferStatus().withLength(random.length);
    new BrickUploadFeature(session, new BrickWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledLoginCallback());
    local.delete();
    assertTrue(new BrickFindFeature(session).find(test));
    final Path copy = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new BrickTouchFeature(session).touch(copy, new TransferStatus());
    new BrickCopyFeature(session).copy(test, copy, new TransferStatus().exists(true), new DisabledConnectionCallback(), new DisabledStreamListener());
    final Find find = new DefaultFindFeature(session);
    assertTrue(find.find(test));
    assertTrue(find.find(copy));
    new BrickDeleteFeature(session).delete(Arrays.asList(test, copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) Local(ch.cyberduck.core.Local) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Find(ch.cyberduck.core.features.Find) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with Local

use of ch.cyberduck.core.Local in project cyberduck by iterate-ch.

the class BrickCopyFeatureTest method testCopyFile.

@Test
public void testCopyFile() throws Exception {
    final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), test.getName());
    final byte[] random = RandomUtils.nextBytes(2547);
    IOUtils.write(random, local.getOutputStream(false));
    final TransferStatus status = new TransferStatus().withLength(random.length);
    new BrickUploadFeature(session, new BrickWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledLoginCallback());
    local.delete();
    assertTrue(new BrickFindFeature(session).find(test));
    final Path copy = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new BrickCopyFeature(session).copy(test, copy, new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
    assertTrue(new BrickFindFeature(session).find(test));
    assertTrue(new BrickFindFeature(session).find(copy));
    new BrickDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    new BrickDeleteFeature(session).delete(Collections.<Path>singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) Local(ch.cyberduck.core.Local) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

Local (ch.cyberduck.core.Local)351 Test (org.junit.Test)306 Path (ch.cyberduck.core.Path)189 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)165 IntegrationTest (ch.cyberduck.test.IntegrationTest)158 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)156 Delete (ch.cyberduck.core.features.Delete)128 Host (ch.cyberduck.core.Host)122 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)109 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)107 BandwidthThrottle (ch.cyberduck.core.io.BandwidthThrottle)99 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)80 TestProtocol (ch.cyberduck.core.TestProtocol)79 InputStream (java.io.InputStream)76 OutputStream (java.io.OutputStream)70 ProtocolFactory (ch.cyberduck.core.ProtocolFactory)69 Credentials (ch.cyberduck.core.Credentials)60 StreamCopier (ch.cyberduck.core.io.StreamCopier)57 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)52 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)51