List of usage examples for org.apache.commons.vfs2 FileObject exists
boolean exists() throws FileSystemException;
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;/*from w ww . ja va 2 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.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"); }//from w w w. ja va2 s. c o m 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
private FileObject getRootDir() throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); if (!rootDir.exists()) { throw new IOException("Root path does not exists"); }/* w w w.j av a 2s. co m*/ if (!isDirectory(rootDir)) { throw new IOException("Root path is not a directory"); } return rootDir; }
From source file:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java
@Override public void save(Note note) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting();/* ww w. j a va 2 s.co 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;//from w ww . ja 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.TemporaryFolderProvider.java
private FileObject getChildFolder(final FileSystemManager fileSystem, final FileObject baseFolder, final String baseName) throws FileSystemException { for (int counter = 0; counter < TEMPORARY_FOLDER_ATTEMPTS; ++counter) { final FileObject temporaryFolder = fileSystem.resolveFile(baseFolder, baseName + counter); if (!temporaryFolder.exists()) { temporaryFolder.createFolder(); return temporaryFolder; }//from w w w . java 2 s . com } throw new FileSystemException("Failed to create directory within " + TEMPORARY_FOLDER_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + (TEMPORARY_FOLDER_ATTEMPTS - 1) + ')'); }
From source file:org.clever.ClusterManager.StorageManagerPlugins.StorageManagerClever.StorageManager.java
/** * This method checks if the path set by the user during registration is valid * @param cleverPath//from w ww . j a v a 2 s . co m * @throws CleverException * @throws FileSystemException * @throws Exception */ @Override public void registerVeNew(String cleverPath) throws CleverException, FileSystemException, Exception { VFSDescription vfsD = discoveryNode(cleverPath, ""); VirtualFileSystem a = new VirtualFileSystem(); a.setURI(vfsD); FileObject file = a.resolver(vfsD, a.getURI(), vfsD.getPath1()); if (!file.exists()) { throw new LogicalCatalogException("file not exist"); } }
From source file:org.clever.Common.Storage.VirtualFileSystem.java
/** * This method lists contents of a file or folder * @param file//from w w w . j a v a2s . c o m * @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//from w w w .j a va 2 s. co m * @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); }
From source file:org.cloudifysource.esc.installer.filetransfer.VfsFileTransfer.java
@Override public void copyFiles(final InstallationDetails details, final Set<String> excludedFiles, final List<File> additionalFiles, final long endTimeMillis) throws TimeoutException, InstallerException { logger.fine("Copying files to: " + host + " from local dir: " + localDir.getName().getPath() + " excluding " + excludedFiles.toString()); try {/*from w w w .j a va 2 s . c o m*/ if (remoteDir.exists()) { FileType type = remoteDir.getType(); if (!type.equals(FileType.FOLDER)) { throw new InstallerException("The remote location: " + remoteDir.getName().getFriendlyURI() + " exists but is not a directory"); } if (deleteRemoteDirectoryContents) { logger.info("Deleting contents of remote directory: " + remoteDir.getName().getFriendlyURI()); remoteDir.delete(new FileDepthSelector(1, Integer.MAX_VALUE)); } FileObject[] children = remoteDir.getChildren(); if (children.length > 0) { throw new InstallerException( "The remote directory: " + remoteDir.getName().getFriendlyURI() + " is not empty"); } } remoteDir.copyFrom(localDir, new FileSelector() { @Override public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { if (excludedFiles.contains(fileInfo.getFile().getName().getBaseName())) { logger.fine(fileInfo.getFile().getName().getBaseName() + " excluded"); return false; } final FileObject remoteFile = fileSystemManager.resolveFile(remoteDir, localDir.getName().getRelativeName(fileInfo.getFile().getName())); if (!remoteFile.exists()) { logger.fine(fileInfo.getFile().getName().getBaseName() + " missing on server"); return true; } if (fileInfo.getFile().getType() == FileType.FILE) { final long remoteSize = remoteFile.getContent().getSize(); final long localSize = fileInfo.getFile().getContent().getSize(); final boolean res = localSize != remoteSize; if (res) { logger.fine(fileInfo.getFile().getName().getBaseName() + " different on server"); } return res; } return false; } @Override public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception { return true; } }); for (final File file : additionalFiles) { logger.fine("copying file: " + file.getAbsolutePath() + " to remote directory"); final FileObject fileObject = fileSystemManager.resolveFile("file:" + file.getAbsolutePath()); final FileObject remoteFile = remoteDir.resolveFile(file.getName()); remoteFile.copyFrom(fileObject, new AllFileSelector()); } logger.fine("Copying files to: " + host + " completed."); } catch (final FileSystemException e) { throw new InstallerException("Failed to copy files to remote host " + host + ": " + e.getMessage(), e); } checkTimeout(endTimeMillis); }