List of usage examples for org.apache.commons.vfs2 FileObject resolveFile
FileObject resolveFile(String name, NameScope scope) throws FileSystemException;
From source file:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
@Override public Note get(String noteId) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD); return getNote(noteDir); }
From source file:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
@Override public void save(Note note) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting();/*from w ww . j a v a 2s .c om*/ Gson gson = gsonBuilder.create(); String json = gson.toJson(note); FileObject rootDir = getRootDir(); FileObject noteDir = rootDir.resolveFile(note.id(), NameScope.CHILD); if (!noteDir.exists()) { noteDir.createFolder(); } if (!isDirectory(noteDir)) { throw new IOException(noteDir.getName().toString() + " is not a directory"); } FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD); // false means not appending. creates file if not exists OutputStream out = noteJson.getContent().getOutputStream(false); out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING))); out.close(); }
From source file:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
@Override public void remove(String noteId) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD); if (!noteDir.exists()) { // nothing to do return;// ww w . ja v a2 s . co m } if (!isDirectory(noteDir)) { // it is not look like zeppelin note savings throw new IOException("Can not remove " + noteDir.getName().toString()); } noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN); }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * Moves the complete content of one directory into another. * * @throws IOException// w w w. jav a 2s. com * If the move failed. */ public static void moveContents(final File sourceDir, final File dest) throws IOException { final FileSystemManager vfsManager = VFSUtilities.getManager(); final FileObject source = vfsManager.toFileObject(sourceDir); final FileObject destDir = vfsManager.toFileObject(dest); final FileObject[] findFiles = source.findFiles(new AllFileSelector()); // Might happen, if source does not exists... shouldn't we check this? if (findFiles == null) return; for (final FileObject fileObject : findFiles) { if (FileType.FILE.equals(fileObject.getType())) { final String relPath = source.getName().getRelativeName(fileObject.getName()); final FileObject destFile = destDir.resolveFile(relPath, NameScope.DESCENDENT_OR_SELF); final FileObject folder = destFile.getParent(); folder.createFolder(); fileObject.moveTo(destFile); } } }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public List<NoteInfo> list() throws IOException { FileObject rootDir = getRootDir(); FileObject projectDir = null; if (this.project != null) { projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); }//w w w. ja va 2 s. co m LinkedList<FileObject> children = getNotes(rootDir, projectDir); List<NoteInfo> infos = new LinkedList<>(); for (FileObject f : children) { String fileName = f.getName().getBaseName(); if (f.isHidden() || fileName.startsWith(".") || fileName.startsWith("#") || fileName.startsWith("~")) { // skip hidden, temporary files continue; } if (!isDirectory(f)) { // currently single note is saved like, [NOTE_ID]/note.json. // so it must be a directory continue; } NoteInfo info = null; try { info = getNoteInfo(f); if (info != null) { infos.add(info); } } catch (IOException e) { logger.error("Can't read note " + f.getName().toString(), e); } } return infos; }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public Note get(String noteId) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); FileObject noteDir = projectDir.resolveFile(noteId, NameScope.CHILD); if (noteDir.exists() && isDirectory(noteDir)) { return getNote(noteDir); }/*ww w . j a v a 2 s. c o m*/ noteDir = rootDir.resolveFile(noteId, NameScope.CHILD); return getNote(noteDir); }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public void save(Note note) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting();/*ww w.j av a2 s . c o m*/ Gson gson = gsonBuilder.create(); String json = gson.toJson(note); FileObject rootDir = getRootDir(); FileObject projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); if (!projectDir.exists()) { projectDir.createFolder(); } if (!isDirectory(projectDir)) { throw new IOException(projectDir.getName().toString() + " is not a directory"); } FileObject noteDir = projectDir.resolveFile(note.id(), NameScope.CHILD); if (!noteDir.exists()) { noteDir.createFolder(); } if (!isDirectory(noteDir)) { throw new IOException(noteDir.getName().toString() + " is not a directory"); } FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD); // false means not appending. creates file if not exists OutputStream out = noteJson.getContent().getOutputStream(false); out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING))); out.close(); noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD)); }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
@Override public void remove(String noteId) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD); if (!projectDir.exists() || !isDirectory(projectDir)) { // no project dir return;//from w ww .j av a 2 s .c o m } FileObject noteDir = projectDir.resolveFile(noteId, NameScope.CHILD); if (!noteDir.exists()) { // nothing to do return; } if (!isDirectory(noteDir)) { // it is not look like zeppelin note savings throw new IOException("Can not remove " + noteDir.getName().toString()); } noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN); }
From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java
private LinkedList<FileObject> getNotes(FileObject root, FileObject proj) throws IOException { FileObject[] rootchildren = root.getChildren(); FileObject[] projChildren;//from w w w.j a v a 2 s .com LinkedList<FileObject> children = new LinkedList<>(); if (isDirectory(proj)) { projChildren = proj.getChildren(); if (projChildren != null) { children = new LinkedList<>(Arrays.asList(projChildren)); } } // add notes in the root dir that are not project specific ex. tutorials for (FileObject f : rootchildren) { if (isDirectory(f)) { FileObject noteJson = f.resolveFile("note.json", NameScope.CHILD); if (noteJson.exists() && !listContainsNote(children, f)) { children.add(f); } } } return children; }