Search in sources :

Example 1 with TransferCanceledException

use of ch.cyberduck.core.exception.TransferCanceledException in project cyberduck by iterate-ch.

the class AbstractTransferWorker method run.

@Override
public Boolean run(final Session<?> source) throws BackgroundException {
    final String lock = sleep.lock();
    final Session<?> destination = this.borrow(Connection.destination);
    try {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Start transfer with prompt %s and options %s", prompt, options));
        }
        // Determine the filter to match files against
        final TransferAction action = transfer.action(source, destination, options.resumeRequested, options.reloadRequested, prompt, new DisabledListProgressListener() {

            @Override
            public void message(final String message) {
                progress.message(message);
            }
        });
        if (log.isDebugEnabled()) {
            log.debug(String.format("Selected transfer action %s", action));
        }
        if (action.equals(TransferAction.cancel)) {
            if (log.isInfoEnabled()) {
                log.info(String.format("Transfer %s canceled by user", this));
            }
            throw new TransferCanceledException();
        }
        // Reset the cached size of the transfer and progress value
        transfer.reset();
        // Normalize Paths before preparing
        transfer.normalize();
        // Calculate information about the files in advance to give progress information
        for (TransferItem next : transfer.getRoots()) {
            this.prepare(next.remote, next.local, new TransferStatus().exists(true), action);
        }
        this.await();
        meter.reset();
        transfer.pre(source, destination, table, connect);
        // Transfer all files sequentially
        for (TransferItem next : transfer.getRoots()) {
            this.transfer(next, action);
        }
        this.await();
        transfer.post(source, destination, table, connect);
    } finally {
        this.release(source, Connection.source, null);
        this.release(destination, Connection.destination, null);
        if (transfer.isReset()) {
            notification.notify(transfer.getName(), transfer.getUuid(), transfer.isComplete() ? String.format("%s complete", StringUtils.capitalize(transfer.getType().name())) : "Transfer incomplete", transfer.getName());
        }
        sleep.release(lock);
        table.clear();
        cache.clear();
    }
    return true;
}
Also used : DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) TransferAction(ch.cyberduck.core.transfer.TransferAction) TransferCanceledException(ch.cyberduck.core.exception.TransferCanceledException) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) TransferItem(ch.cyberduck.core.transfer.TransferItem)

Example 2 with TransferCanceledException

use of ch.cyberduck.core.exception.TransferCanceledException in project cyberduck by iterate-ch.

the class EueWriteFeatureTest method testWriteCancel.

@Test(expected = TransferCanceledException.class)
public void testWriteCancel() throws Exception {
    final EueResourceIdProvider fileid = new EueResourceIdProvider(session);
    final EueWriteFeature writer = new EueWriteFeature(session, fileid);
    final byte[] content = RandomUtils.nextBytes(32769);
    final Path test = new Path(String.format("{%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
    {
        final BytecountStreamListener count = new BytecountStreamListener();
        final TransferStatus status = new TransferStatus() {

            @Override
            public void validate() throws ConnectionCanceledException {
                if (count.getSent() >= 32768) {
                    throw new TransferCanceledException();
                }
                super.validate();
            }
        };
        status.setLength(content.length);
        final StatusOutputStream<EueWriteFeature.Chunk> out = writer.write(test, status, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).withListener(count).transfer(new ByteArrayInputStream(content), out);
        assertFalse(new DefaultFindFeature(session).find(test));
        try {
            out.getStatus();
            fail();
        } catch (TransferCanceledException e) {
        // 
        }
    }
    // Rewrite
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final StatusOutputStream<EueWriteFeature.Chunk> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    assertFalse(new DefaultFindFeature(session).find(test));
    new EueDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : AbstractPath(ch.cyberduck.core.AbstractPath) Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) ConnectionCanceledException(ch.cyberduck.core.exception.ConnectionCanceledException) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) TransferCanceledException(ch.cyberduck.core.exception.TransferCanceledException) 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) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with TransferCanceledException

use of ch.cyberduck.core.exception.TransferCanceledException in project cyberduck by iterate-ch.

the class StoregateWriteFeatureTest method testWriteCancel.

@Test(expected = TransferCanceledException.class)
public void testWriteCancel() throws Exception {
    final StoregateIdProvider nodeid = new StoregateIdProvider(session);
    final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir(new Path(String.format("/My files/%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(32769);
    final Path test = new Path(room, String.format("{%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
    final BytecountStreamListener listener = new BytecountStreamListener();
    final TransferStatus status = new TransferStatus() {

        @Override
        public void validate() throws ConnectionCanceledException {
            if (listener.getSent() >= 32768) {
                throw new TransferCanceledException();
            }
            super.validate();
        }
    };
    status.setLength(content.length);
    final StoregateWriteFeature writer = new StoregateWriteFeature(session, nodeid);
    final HttpResponseOutputStream<FileMetadata> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).withListener(listener).transfer(new ByteArrayInputStream(content), out);
    assertFalse(new DefaultFindFeature(session).find(test));
    out.getStatus();
    new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) TransferCanceledException(ch.cyberduck.core.exception.TransferCanceledException) FileMetadata(ch.cyberduck.core.storegate.io.swagger.client.model.FileMetadata) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with TransferCanceledException

use of ch.cyberduck.core.exception.TransferCanceledException in project cyberduck by iterate-ch.

the class StoregateMultipartWriteFeatureTest method testWriteCancel.

@Test(expected = TransferCanceledException.class)
public void testWriteCancel() throws Exception {
    final StoregateIdProvider nodeid = new StoregateIdProvider(session);
    final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir(new Path(String.format("/My files/%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(32769);
    final Path test = new Path(room, String.format("{%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
    final BytecountStreamListener listener = new BytecountStreamListener();
    final TransferStatus status = new TransferStatus() {

        @Override
        public void validate() throws ConnectionCanceledException {
            if (listener.getSent() >= 32768) {
                throw new TransferCanceledException();
            }
            super.validate();
        }
    };
    status.setLength(content.length);
    final StoregateMultipartWriteFeature writer = new StoregateMultipartWriteFeature(session, nodeid);
    final HttpResponseOutputStream<FileMetadata> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).withListener(listener).transfer(new ByteArrayInputStream(content), out);
    assertFalse(new DefaultFindFeature(session).find(test));
    out.getStatus();
}
Also used : Path(ch.cyberduck.core.Path) TransferCanceledException(ch.cyberduck.core.exception.TransferCanceledException) FileMetadata(ch.cyberduck.core.storegate.io.swagger.client.model.FileMetadata) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) 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 5 with TransferCanceledException

use of ch.cyberduck.core.exception.TransferCanceledException in project cyberduck by iterate-ch.

the class SDSMultipartWriteFeatureTest method testWriteCancel.

@Test(expected = TransferCanceledException.class)
public void testWriteCancel() throws Exception {
    final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session);
    final Path room = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(32769);
    final Path test = new Path(room, String.format("{%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
    final BytecountStreamListener count = new BytecountStreamListener();
    final TransferStatus status = new TransferStatus() {

        @Override
        public void validate() throws ConnectionCanceledException {
            if (count.getSent() >= 32768) {
                throw new TransferCanceledException();
            }
            super.validate();
        }
    };
    status.setLength(content.length);
    final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session, nodeid);
    final StatusOutputStream<Node> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).withListener(count).transfer(new ByteArrayInputStream(content), out);
    assertFalse(new DefaultFindFeature(session).find(test));
    out.getStatus();
}
Also used : Path(ch.cyberduck.core.Path) Node(ch.cyberduck.core.sds.io.swagger.client.model.Node) TransferCanceledException(ch.cyberduck.core.exception.TransferCanceledException) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) 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)

Aggregations

TransferCanceledException (ch.cyberduck.core.exception.TransferCanceledException)6 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)6 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)5 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)4 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)4 Path (ch.cyberduck.core.Path)4 StreamCopier (ch.cyberduck.core.io.StreamCopier)4 DefaultFindFeature (ch.cyberduck.core.shared.DefaultFindFeature)4 IntegrationTest (ch.cyberduck.test.IntegrationTest)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Test (org.junit.Test)4 Delete (ch.cyberduck.core.features.Delete)2 FileMetadata (ch.cyberduck.core.storegate.io.swagger.client.model.FileMetadata)2 TransferItem (ch.cyberduck.core.transfer.TransferItem)2 AbstractPath (ch.cyberduck.core.AbstractPath)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)1 Session (ch.cyberduck.core.Session)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1