List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:org.apache.zeppelin.notebook.repo.OldVFSNotebookRepo.java
private Note getNote(FileObject noteDir) throws IOException { if (!isDirectory(noteDir)) { throw new IOException(noteDir.getName().toString() + " is not a directory"); }// ww w . j a v a 2s . c o m FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD); if (!noteJson.exists()) { throw new IOException(noteJson.getName().toString() + " not found"); } FileContent content = noteJson.getContent(); InputStream ins = content.getInputStream(); String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING)); ins.close(); return Note.fromJson(json); }
From source file:org.apache.zeppelin.notebook.repo.OldVFSNotebookRepo.java
@Override public synchronized void save(Note note, AuthenticationInfo subject) throws IOException { LOG.info("Saving note:" + note.getId()); String json = note.toJson();/*from w w w .j a va2 s. co m*/ FileObject rootDir = getRootDir(); FileObject noteDir = rootDir.resolveFile(note.getId(), 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:org.apache.zeppelin.notebook.repo.OldVFSNotebookRepo.java
@Override public void remove(String noteId, AuthenticationInfo subject) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD); if (!noteDir.exists()) { // nothing to do return;/* w w w. java2s. c om*/ } 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.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
@Override public List<NoteInfo> list() throws IOException { FileObject rootDir = getRootDir(); FileObject[] children = rootDir.getChildren(); List<NoteInfo> infos = new LinkedList<NoteInfo>(); for (FileObject f : children) { String fileName = f.getName().getBaseName(); if (f.isHidden() || fileName.startsWith(".") || fileName.startsWith("#") || fileName.startsWith("~")) { // skip hidden, temporary files continue; }//from www.j a v a 2 s .c o m 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:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
private Note getNote(FileObject noteDir) throws IOException { if (!isDirectory(noteDir)) { throw new IOException(noteDir.getName().toString() + " is not a directory"); }/* www .j a v a2 s. c om*/ FileObject noteJson = noteDir.resolveFile("note.json", NameScope.CHILD); if (!noteJson.exists()) { throw new IOException(noteJson.getName().toString() + " not found"); } GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); FileContent content = noteJson.getContent(); InputStream ins = content.getInputStream(); String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING)); ins.close(); Note note = gson.fromJson(json, Note.class); // note.setReplLoader(replLoader); // note.jobListenerFactory = jobListenerFactory; for (Paragraph p : note.getParagraphs()) { if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) { p.setStatus(Status.ABORT); } } return note; }
From source file:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
@Override public void save(Note note) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting();/*w w w. j av a2s . c o m*/ 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. j a v a 2s .c o 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.celeria.minecraft.backup.ArchiveWorldTask.java
private String relativeNameOf(final FileObject baseFolder, final FileObject file) throws FileSystemException { return baseFolder.getName().getRelativeName(file.getName()); }
From source file:org.clever.Common.Storage.VirtualFileSystem.java
/** * This method lists contents of a file or folder * @param file//from ww w. j a va 2 s . c om * @return * @throws FileSystemException */ public String ls(FileObject file) throws FileSystemException { String str = "Contents of " + file.getName() + "\n"; if (file.exists()) { if (file.getType().equals(FileType.FILE)) { str = str + "Size: " + file.getContent().getSize() + " bytes\n" + "Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime())) + "\n" + "Readable: " + file.isReadable() + "\n" + "Writeable: " + file.isWriteable() + "\n"; return str; } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); str = str = "Directory with " + children.length + " files \n" + "Readable: " + file.isReadable() + "\n" + "Writeable: " + file.isWriteable() + "\n\n"; //str=str+"Last modified: " +DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))+"\n" ; for (int i = 0; i < children.length; i++) { str = str + children[i].getName().getBaseName() + "\n"; } } } else { str = str + "The file does not exist"; } return str; }
From source file:org.clever.Common.Storage.VirtualFileSystem.java
/** * This method copies a file or folder// w w w . j a v a2s . c om * @param file_s * @param file_d * @throws FileSystemException */ public void cp(FileObject file_s, FileObject file_d) throws FileSystemException { if (file_d.exists() && file_d.getType() == FileType.FOLDER) { file_d = file_d.resolveFile(file_s.getName().getBaseName()); } file_d.copyFrom(file_s, Selectors.SELECT_ALL); }