protected Path expand(final Path remote, final String format) { if(remote.getAbsolute().startsWith(format)) { return new Path(StringUtils.replaceOnce(remote.getAbsolute(), format, workdir.getAbsolute()), remote.getType()); } return remote; } }
/** * @return the path relative to its parent directory */ @Override public String getName() { if(this.isRoot()) { return String.valueOf(DELIMITER); } final String abs = this.getAbsolute(); int index = abs.lastIndexOf(DELIMITER); return abs.substring(index + 1); }
private List<Path> findObjectsAsPaths(final Path workdir, final Predicate<MantaObject> searchPredicate) { return session.getClient().find(workdir.getAbsolute(), searchPredicate) .map(adapter::toPath) .collect(Collectors.toList()); }
public OneDriveFolder toFolder(final Path file, final boolean resolveLastItem) throws BackgroundException { final OneDriveItem item = this.toItem(file, resolveLastItem); if(!(item instanceof OneDriveFolder)) { throw new NotfoundException(String.format("%s is not a folder.", file.getAbsolute())); } return (OneDriveFolder) item; }
public OneDriveFile toFile(final Path file, final boolean resolveLastItem) throws BackgroundException { final OneDriveItem item = this.toItem(file, resolveLastItem); if(!(item instanceof OneDriveFile)) { throw new NotfoundException(String.format("%s is not a file.", file.getAbsolute())); } return (OneDriveFile) item; }
public SimplePathPredicate(final Path file) { this.file = file; this.type = file.isSymbolicLink() ? Path.Type.symboliclink : file.isFile() ? Path.Type.file : Path.Type.directory; this.path = file.getAbsolute(); }
@Override public boolean find(final Path file) { return session.getClient().existsAndIsAccessible(file.getAbsolute()); } }
/** * @param path Filename * @return Unarchive command */ public String getDecompressCommand(final Path path) { return MessageFormat.format(preferences.getProperty(String.format("archive.command.expand.%s", this.getIdentifier())), this.escape(path.getAbsolute()), this.escape(path.getParent().getAbsolute())); }
@Override public <T> T serialize(final Serializer dict) { dict.setStringForKey(String.valueOf(type), "Type"); dict.setStringForKey(this.getAbsolute(), "Remote"); if(symlink != null) { dict.setObjectForKey(symlink, "Symbolic Link"); } dict.setObjectForKey(attributes, "Attributes"); return dict.getSerialized(); }
@Override public void symlink(final Path file, String target) throws BackgroundException { try { session.sftp().symlink(target, file.getAbsolute()); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } }
@Override public InputStream execute() throws BackgroundException { try { return session.getClient().retrieveFileStream(file.getAbsolute()); } catch(IOException e) { throw new FTPExceptionMappingService().map(e); } } }, new DisabledProgressListener());
@Override public void setUnixOwner(final Path file, final String owner) throws BackgroundException { final FileAttributes attr = new FileAttributes.Builder() .withUIDGID(new Integer(owner), 0) .build(); try { session.sftp().setAttributes(file.getAbsolute(), attr); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); final DescriptiveUrl base = this.toUrl(); list.add(new DescriptiveUrl(URI.create(String.format("%s%s", base.getUrl(), URIEncoder.encode( PathNormalizer.normalize(PathRelativizer.relativize(PathNormalizer.normalize(host.getDefaultPath(), true), file.getAbsolute())) ))).normalize(), base.getType(), base.getHelp()) ); return list; }
@Override public PathAttributes find(final Path file) throws BackgroundException { try { final Metadata metadata = new DbxUserFilesRequests(session.getClient()).getMetadata(file.getAbsolute()); return this.toAttributes(metadata); } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
@Override public void symlink(Path file, String target) throws BackgroundException { try { if(!session.getClient().sendSiteCommand(String.format("SYMLINK %s %s", file.getAbsolute(), target))) { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } } catch(IOException e) { throw new FTPExceptionMappingService().map("Cannot create file {0}", e, file); } } }
private void addNavigation(final Path p) { pathPopupButton.addItemWithTitle(p.getAbsolute()); pathPopupButton.lastItem().setRepresentedObject(p.getAbsolute()); if(p.isVolume()) { pathPopupButton.lastItem().setImage(IconCacheFactory.<NSImage>get().volumeIcon(pool.getHost().getProtocol(), 16)); } else { pathPopupButton.lastItem().setImage(IconCacheFactory.<NSImage>get().fileIcon(p, 16)); } }
protected boolean isWorldReadable(final MantaObject object) { final MantaAccountHomeInfo accountHomeInfo = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return StringUtils.startsWithAny( object.getPath(), accountHomeInfo.getAccountPublicRoot().getAbsolute()); }
public GotoController(final BrowserController parent, final Cache<Path> cache) { this.parent = parent; this.cache = cache; folderCombobox = NSComboBox.textfieldWithFrame(new NSRect(0, 26)); folderCombobox.setCompletes(true); folderCombobox.setUsesDataSource(true); folderComboboxModel = new FolderComboboxModel(parent.workdir()); folderCombobox.setDataSource(folderComboboxModel.id()); folderCombobox.setStringValue(parent.workdir().getAbsolute()); }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { final CreateFolderResult result = new DbxUserFilesRequests(session.getClient()).createFolderV2(folder.getAbsolute(), false); return new Path(folder.getParent(), folder.getName(), folder.getType(), new DropboxAttributesFinderFeature(session).toAttributes(result.getMetadata())); } catch(DbxException e) { throw new DropboxExceptionMappingService().map(e); } }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(!session.getClient().makeDirectory(folder.getAbsolute())) { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } } catch(IOException e) { throw new FTPExceptionMappingService().map("Cannot create folder {0}", e, folder); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new DefaultAttributesFinderFeature(session).find(folder)); }