use of ch.cyberduck.core.transfer.download.DownloadFilterOptions in project cyberduck by iterate-ch.
the class TerminalTransferFactory method create.
public Transfer create(final CommandLine input, final Host host, final Path remote, final List<TransferItem> items) throws BackgroundException {
final Transfer transfer;
final TerminalAction type = TerminalActionFinder.get(input);
if (null == type) {
throw new BackgroundException(LocaleFactory.localizedString("Unknown"), "Unknown transfer type");
}
switch(type) {
case download:
if (StringUtils.containsAny(remote.getName(), '*')) {
transfer = new DownloadTransfer(host, items, new DownloadGlobFilter(remote.getName()));
} else {
transfer = new DownloadTransfer(host, items);
}
if (input.hasOption(TerminalOptionsBuilder.Params.nochecksum.name())) {
final DownloadFilterOptions options = new DownloadFilterOptions(host);
options.checksum = Boolean.parseBoolean(input.getOptionValue(TerminalOptionsBuilder.Params.nochecksum.name()));
((DownloadTransfer) transfer).withOptions(options);
}
break;
case upload:
transfer = new UploadTransfer(host, items);
if (input.hasOption(TerminalOptionsBuilder.Params.nochecksum.name())) {
final UploadFilterOptions options = new UploadFilterOptions(host);
options.checksum = Boolean.parseBoolean(input.getOptionValue(TerminalOptionsBuilder.Params.nochecksum.name()));
((UploadTransfer) transfer).withOptions(options);
}
break;
case synchronize:
transfer = new SyncTransfer(host, items.iterator().next());
break;
default:
throw new BackgroundException(LocaleFactory.localizedString("Unknown"), String.format("Unknown transfer type %s", type.name()));
}
if (input.hasOption(TerminalOptionsBuilder.Params.throttle.name())) {
try {
transfer.setBandwidth(Float.parseFloat(input.getOptionValue(TerminalOptionsBuilder.Params.throttle.name())));
} catch (NumberFormatException ignore) {
//
}
}
return transfer;
}
use of ch.cyberduck.core.transfer.download.DownloadFilterOptions in project cyberduck by iterate-ch.
the class DownloadTransferTest method testPrepareDownloadResumeFilter.
@Test
public void testPrepareDownloadResumeFilter() throws Exception {
final Host host = new Host(new TestProtocol());
final Session<?> session = new NullTransferSession(host);
final Path test = new Path("/transfer/test", EnumSet.of(Path.Type.file));
test.attributes().setSize(5L);
final Local local = new Local(System.getProperty("java.io.tmpdir") + "/transfer/" + UUID.randomUUID().toString());
LocalTouchFactory.get().touch(local);
final OutputStream out = local.getOutputStream(false);
IOUtils.write("test", out, Charset.defaultCharset());
out.close();
final Transfer transfer = new DownloadTransfer(host, test, local) {
@Override
public AbstractDownloadFilter filter(final Session<?> source, final Session<?> d, final TransferAction action, final ProgressListener listener) {
return new ResumeFilter(new DownloadSymlinkResolver(Collections.singletonList(new TransferItem(test))), new NullTransferSession(new Host(new TestProtocol())), new DownloadFilterOptions(host), new DefaultDownloadFeature(source.getFeature(Read.class)) {
@Override
public boolean offset(final Path file) {
return true;
}
});
}
};
final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
fail();
return null;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService());
worker.prepare(test, local, new TransferStatus().exists(true), TransferAction.resume);
final TransferStatus status = new TransferStatus();
status.setExists(true);
final TransferStatus expected = new TransferStatus();
expected.setAppend(true);
expected.setExists(true);
expected.setOffset("test".getBytes().length);
// Transfer length
expected.setLength(5L - "test".getBytes().length);
assertEquals(expected, worker.getStatus().get(new TransferItem(test, local)));
local.delete();
}
use of ch.cyberduck.core.transfer.download.DownloadFilterOptions in project cyberduck by iterate-ch.
the class BrowserTableDataSource method namesOfPromisedFilesDroppedAtDestination.
/**
* @return the names (not full paths) of the files that the receiver promises to create at dropDestination. This
* method is invoked when the drop has been accepted by the destination and the destination, in the case of another
* Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination. For long
* operations, you can cache dropDestination and defer the creation of the files until the finishedDraggingImage
* method to avoid blocking the destination application.
*/
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL url) {
if (log.isDebugEnabled()) {
log.debug(String.format("Return names of promised files dropped at %s", url));
}
NSMutableArray promisedDragNames = NSMutableArray.array();
if (null != url) {
final Local destination = LocalFactory.get(url.path());
final DownloadFilterOptions options = new DownloadFilterOptions(controller.getSession().getHost());
if (destination.isChild(new TemporarySupportDirectoryFinder().find())) {
options.icon = false;
options.segments = false;
}
final PathPasteboard pasteboard = controller.getPasteboard();
final List<TransferItem> downloads = new ArrayList<TransferItem>();
for (Path p : pasteboard) {
downloads.add(new TransferItem(p, LocalFactory.get(destination, p.getName())));
// Add to returned path names
promisedDragNames.addObject(p.getName());
}
if (downloads.size() == 1) {
if (downloads.iterator().next().remote.isFile()) {
final Local file = downloads.iterator().next().local;
if (!file.exists()) {
try {
LocalTouchFactory.get().touch(file);
if (options.icon) {
IconServiceFactory.get().set(file, new TransferStatus().withLength(0L));
}
} catch (AccessDeniedException e) {
log.warn(String.format("Failure creating file %s %s", file, e.getMessage()));
}
}
}
if (downloads.iterator().next().remote.isDirectory()) {
final Local file = downloads.iterator().next().local;
if (!file.exists()) {
try {
new DefaultLocalDirectoryFeature().mkdir(file);
} catch (AccessDeniedException e) {
log.warn(e.getMessage());
}
}
}
}
// kTemporaryFolderType
final boolean dock = destination.equals(LocalFactory.get("~/Library/Caches/TemporaryItems"));
if (dock) {
for (Path p : pasteboard) {
// Drag to application icon in dock.
controller.edit(p);
}
} else {
final Transfer transfer = new DownloadTransfer(controller.getSession().getHost(), downloads).withOptions(options);
controller.transfer(transfer, Collections.emptyList());
}
pasteboard.clear();
}
// Filenames
return promisedDragNames;
}
Aggregations