/** * @param file A valid bookmark dictionary * @return Null if the file cannot be deserialized * @throws AccessDeniedException If the file is not readable */ @Override public S read(final Local file) throws AccessDeniedException { if(!file.exists()) { throw new LocalAccessDeniedException(file.getAbsolute()); } if(!file.isFile()) { throw new LocalAccessDeniedException(file.getAbsolute()); } final S deserialized = this.read(file.getInputStream()); if(null == deserialized) { throw new AccessDeniedException(String.format("Failure parsing file %s", file.getName())); } return deserialized; }
public String getLocal() { final Local local = roots.iterator().next().local; if(roots.size() == 1) { return local.getAbbreviatedPath(); } else { return local.getParent().getAbbreviatedPath(); } }
@Override public boolean accept(Local file) { if(file.isDirectory()) { return true; } return "xml".equals(file.getExtension()); }
@Override public int compare(final Local o1, final Local o2) { if(o1.isDirectory() && o2.isDirectory()) { return 0; } if(o1.isFile() && o2.isFile()) { return 0; } if(o1.isDirectory()) { return -1; } if(o2.isDirectory()) { return 1; } return 0; } }
@Override public void run() { final NSOpenPanel panel = NSOpenPanel.openPanel(); panel.setCanChooseDirectories(file.isDirectory()); panel.setCanChooseFiles(file.isFile()); panel.setAllowsMultipleSelection(false); panel.setMessage(MessageFormat.format(LocaleFactory.localizedString("Select {0}", "Credentials"), file.getAbbreviatedPath())); panel.setPrompt(LocaleFactory.localizedString("Choose")); final NSInteger modal = panel.runModal(file.getParent().getAbsolute(), file.getName()); if(modal.intValue() == SheetCallback.DEFAULT_OPTION) { final NSArray filenames = panel.filenames(); final NSEnumerator enumerator = filenames.objectEnumerator(); NSObject next; while((next = enumerator.nextObject()) != null) { selected.set(new FinderLocal(next.toString())); } } panel.orderOut(null); } };
private Properties load() { final Properties properties = new Properties(); try { new DefaultLocalDirectoryFeature().mkdir(file.getParent()); } catch(AccessDeniedException e) { log.warn(String.format("Failure saving credentials to %s. %s", file.getAbsolute(), e.getDetail())); } if(file.exists()) { try { try (InputStream in = file.getInputStream()) { properties.load(in); } } catch(AccessDeniedException e) { log.warn(String.format("Failure reading credentials from %s. %s", file.getAbsolute(), e.getDetail())); } catch(IOException e) { log.warn(String.format("Failure reading credentials from %s. %s", file.getAbsolute(), e.getMessage())); } } return properties; }
public InputStream getInputStream() throws AccessDeniedException { return this.getInputStream(path); }
@Override public void trash(Local file) throws LocalAccessDeniedException { try { Files.delete(Paths.get(file.getAbsolute())); } catch(IOException e) { throw new LocalAccessDeniedException(String.format("Failed to move %s to Trash", file.getName()), e); } } }
String passphrase = this.getPassword(bookmark.getHostname(), key.getAbbreviatedPath()); if(null == passphrase) { passphrase = this.getPassword("SSH", key.getAbsolute()); passphrase = this.getPassword("SSHKeychain", key.getAbbreviatedPath());
@Override public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException { if(local.isFile()) { if(local.exists()) { if(local.attributes().getSize() == attributes.getSize()) { if(Checksum.NONE != attributes.getChecksum()) { final ChecksumCompute compute = ChecksumComputeFactory.get(attributes.getChecksum().algorithm); if(compute.compute(local.getInputStream(), parent).equals(attributes.getChecksum())) { if(log.isInfoEnabled()) { log.info(String.format("Skip file %s with checksum %s", file, local.attributes().getChecksum())); log.info(String.format("Skip file %s with local size %d", file, local.attributes().getSize()));
for(TransferItem download : roots) { final Local local = download.local; if(local.exists()) { if(local.isDirectory()) { if(local.list().isEmpty()) { if(local.isFile()) { if(local.attributes().getSize() == 0) {
@Override public void load() throws AccessDeniedException { if(log.isInfoEnabled()) { log.info(String.format("Reloading %s", folder.getAbsolute())); if(!folder.exists()) { new DefaultLocalDirectoryFeature().mkdir(folder); final AttributedList<Local> transfers = folder.list().filter( new Filter<Local>() { @Override final Transfer transfer = reader.read(f); if(!this.getFile(transfer).equals(f)) { this.rename(f, transfer);
@Override public boolean open(final Local file) { try { runtime.exec(String.format("xdg-open %s", file.getAbsolute())); return true; } catch(IOException e) { log.warn(String.format("Failure launching application %s", e.getMessage())); return false; } }
protected boolean matches(final Local context, final Local file) { if(!new File(context.getAbsolute()).isAbsolute()) { return context.getName().equals(file.getName()); } return this.normalize(context).equals(this.normalize(file)); }
@Override public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException { final Local volume = local.getVolume(); if(!volume.exists()) { throw new NotfoundException(String.format("Volume %s not mounted", volume.getAbsolute())); } return true; }
@Override public void load() throws AccessDeniedException { if(log.isInfoEnabled()) { log.info(String.format("Reloading %s", folder.getAbsolute())); if(!folder.exists()) { new DefaultLocalDirectoryFeature().mkdir(folder); final AttributedList<Local> bookmarks = folder.list().filter( new Filter<Local>() { @Override
@Override public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException { if(!local.exists()) { // Local file is no more here throw new NotfoundException(local.getAbsolute()); } return true; }
@Override public List<TransferItem> list(final Session<?> session, final Path remote, final Local directory, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List children for %s", directory)); } if(directory.isSymbolicLink()) { final Symlink symlink = session.getFeature(Symlink.class); if(new UploadSymlinkResolver(symlink, roots).resolve(directory)) { if(log.isDebugEnabled()) { log.debug(String.format("Do not list children for symbolic link %s", directory)); } // We can resolve the target of the symbolic link and will create a link on the remote system // using the symlink feature of the session return Collections.emptyList(); } } final List<TransferItem> children = new ArrayList<TransferItem>(); for(Local local : directory.list().filter(comparator, filter)) { children.add(new TransferItem(new Path(remote, local.getName(), local.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file)), local)); } return children; }
@Override public Comparison compare(final Path file, final Local local) throws BackgroundException { if(local.exists()) { if(finder.withCache(cache).find(file)) { if(file.isDirectory()) { switch(size.compare(attributes, local.attributes())) { case remote: return Comparison.remote; local.attributes().setChecksum(ChecksumComputeFactory.get(attributes.getChecksum().algorithm) .compute(local.getInputStream(), new TransferStatus())); switch(checksum.compare(attributes, local.attributes())) { case equal: final Comparison compare = timestamp.compare(attributes, local.attributes()); switch(compare) { case unknown: switch(size.compare(attributes, local.attributes())) { case local: case notequal: