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;
}
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());
}
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());
}
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();
}
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();
}
Aggregations