Search in sources :

Example 1 with StatusOutputStream

use of ch.cyberduck.core.io.StatusOutputStream 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)

Example 2 with StatusOutputStream

use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.

the class BufferWriteFeatureTest method testWriteVault.

@Test
public void testWriteVault() 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 BufferWriteFeature(session), cryptomator);
    final byte[] content = RandomUtils.nextBytes(1024 * 1024);
    final TransferStatus writeStatus = new TransferStatus();
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    writeStatus.setNonces(new RandomNonceGenerator());
    writeStatus.setChecksum(feature.checksum(test, new TransferStatus()).compute(new ByteArrayInputStream(content), new TransferStatus()));
    writeStatus.setLength(content.length);
    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());
    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) 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) BufferWriteFeature(ch.cyberduck.core.shared.BufferWriteFeature) 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)

Example 3 with StatusOutputStream

use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.

the class BufferWriteFeatureTest method testWriteOverwrite.

@Test
public void testWriteOverwrite() throws Exception {
    final BoxFileidProvider fileid = new BoxFileidProvider(session);
    final BufferWriteFeature feature = new BufferWriteFeature(session);
    final Path file = new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    {
        final byte[] content = RandomUtils.nextBytes(42512);
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        final StatusOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
        final ByteArrayInputStream in = new ByteArrayInputStream(content);
        new StreamCopier(status, status).transfer(in, out);
        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);
    }
    {
        final byte[] content = RandomUtils.nextBytes(33221);
        final TransferStatus status = new TransferStatus().exists(true);
        status.setLength(content.length);
        final StatusOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
        final ByteArrayInputStream in = new ByteArrayInputStream(content);
        new StreamCopier(status, status).transfer(in, out);
        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) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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 4 with StatusOutputStream

use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.

the class DefaultCopyFeature method copy.

@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
    InputStream in;
    StatusOutputStream out;
    in = from.getFeature(Read.class).read(source, new TransferStatus(status), callback);
    Write write = to.getFeature(MultipartWrite.class);
    if (null == write) {
        // Fallback if multipart write is not available
        write = to.getFeature(Write.class);
    }
    out = write.write(target, status, callback);
    new StreamCopier(status, status).withListener(listener).transfer(in, out);
    return target.withAttributes(status.getResponse());
}
Also used : Write(ch.cyberduck.core.features.Write) MultipartWrite(ch.cyberduck.core.features.MultipartWrite) InputStream(java.io.InputStream) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) StreamCopier(ch.cyberduck.core.io.StreamCopier)

Example 5 with StatusOutputStream

use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.

the class RenameExistingFilterTest method testTemporaryDirectoryUpload.

@Test
public void testTemporaryDirectoryUpload() throws Exception {
    final Path file = new Path("/t", EnumSet.of(Path.Type.directory));
    final AtomicBoolean found = new AtomicBoolean();
    final AtomicBoolean moved = new AtomicBoolean();
    final Find find = new Find() {

        @Override
        public boolean find(final Path f, final ListProgressListener listener) {
            if (f.equals(file)) {
                found.set(true);
                return true;
            }
            return false;
        }
    };
    final AttributesFinder attributes = new AttributesFinder() {

        @Override
        public PathAttributes find(final Path file, final ListProgressListener listener) {
            return new PathAttributes();
        }
    };
    final Host host = new Host(new TestProtocol());
    final NullSession session = new NullSession(host) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type.equals(Move.class)) {
                return (T) new Move() {

                    @Override
                    public Path move(final Path f, final Path renamed, TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
                        assertFalse(moved.get());
                        assertEquals(file, f);
                        moved.set(true);
                        return renamed;
                    }

                    @Override
                    public boolean isRecursive(final Path source, final Path target) {
                        return true;
                    }
                };
            }
            if (type.equals(Write.class)) {
                return (T) new Write<Void>() {

                    @Override
                    public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
                        fail();
                        return null;
                    }

                    @Override
                    public Append append(final Path file, final TransferStatus status) {
                        fail();
                        return new Append(false);
                    }
                };
            }
            return null;
        }
    };
    final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, new UploadFilterOptions(host).withTemporary(true));
    f.withFinder(find).withAttributes(attributes);
    final TransferStatus status = f.prepare(file, new NullLocal("/t") {

        @Override
        public boolean isDirectory() {
            return true;
        }

        @Override
        public boolean isFile() {
            return false;
        }
    }, new TransferStatus().exists(true), new DisabledProgressListener());
    assertTrue(found.get());
    assertNull(status.getRename().remote);
    assertNull(status.getRename().local);
    assertFalse(moved.get());
    f.apply(file, new NullLocal("/t") {

        @Override
        public boolean isDirectory() {
            return true;
        }
    }, new TransferStatus().exists(true), new DisabledProgressListener());
    assertTrue(moved.get());
}
Also used : Delete(ch.cyberduck.core.features.Delete) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) NullSession(ch.cyberduck.core.NullSession) Move(ch.cyberduck.core.features.Move) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) PathAttributes(ch.cyberduck.core.PathAttributes) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Find(ch.cyberduck.core.features.Find) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Test(org.junit.Test)

Aggregations

StatusOutputStream (ch.cyberduck.core.io.StatusOutputStream)23 Delete (ch.cyberduck.core.features.Delete)21 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)21 Test (org.junit.Test)20 Path (ch.cyberduck.core.Path)18 StreamCopier (ch.cyberduck.core.io.StreamCopier)17 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)16 IntegrationTest (ch.cyberduck.test.IntegrationTest)16 ByteArrayInputStream (java.io.ByteArrayInputStream)16 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)15 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)15 InputStream (java.io.InputStream)12 Host (ch.cyberduck.core.Host)8 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)7 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)7 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)6 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)6 Local (ch.cyberduck.core.Local)6 PathAttributes (ch.cyberduck.core.PathAttributes)6 DefaultAttributesFinderFeature (ch.cyberduck.core.shared.DefaultAttributesFinderFeature)6