List of usage examples for org.apache.commons.vfs FileObject delete
public boolean delete() throws FileSystemException;
From source file:org.pentaho.hdfs.vfs.test.HDFSVFSTest.java
@Test public void renameFile() throws Exception { assertNotNull("FileSystemManager is null", fsManager); FileObject file = fsManager.resolveFile(buildHDFSURL("/junit/name.txt")); assertNotNull("File is null (could not resolve?)", file); assertEquals(FileType.IMAGINARY, file.getType()); OutputStream output = file.getContent().getOutputStream(); IOUtils.write(HELLO_HADOOP_STR, output); IOUtils.closeQuietly(output);//from ww w .j a v a2s. c om assertEquals(FileType.FILE, file.getType()); FileObject renamedFile = fsManager.resolveFile(buildHDFSURL("/junit/renamed.txt")); assertNotNull("File is null (could not resolve?)", renamedFile); assertEquals(FileType.IMAGINARY, renamedFile.getType()); file.moveTo(renamedFile); renamedFile = fsManager.resolveFile(buildHDFSURL("/junit/renamed.txt")); assertNotNull("File is null (could not resolve?)", renamedFile); assertEquals(FileType.FILE, renamedFile.getType()); assertEquals(true, renamedFile.delete()); }
From source file:org.pentaho.hdfs.vfs.test.HDFSVFSTest.java
@Test public void listChildren() throws Exception { assertNotNull("FileSystemManager is null", fsManager); FileObject folder = fsManager.resolveFile(buildHDFSURL("/junit/folder")); assertNotNull("File is null (could not resolve?)", folder); assertEquals(FileType.IMAGINARY, folder.getType()); folder.createFolder();//from w w w.ja va 2 s . c o m folder = fsManager.resolveFile(buildHDFSURL("/junit/folder")); assertEquals(FileType.FOLDER, folder.getType()); FileObject child1 = fsManager.resolveFile(buildHDFSURL("/junit/folder/child1.txt")); assertNotNull("File is null (could not resolve?)", child1); OutputStream output = child1.getContent().getOutputStream(); IOUtils.write(HELLO_HADOOP_STR, output); IOUtils.closeQuietly(output); String fileStr = IOUtils.toString(child1.getContent().getInputStream(), "UTF-8"); assertEquals(HELLO_HADOOP_STR, fileStr); FileObject child2 = fsManager.resolveFile(buildHDFSURL("/junit/folder/child2.txt")); assertNotNull("File is null (could not resolve?)", child2); output = child2.getContent().getOutputStream(); IOUtils.write(HELLO_HADOOP_STR, output); IOUtils.closeQuietly(output); fileStr = IOUtils.toString(child2.getContent().getInputStream(), "UTF-8"); assertEquals(HELLO_HADOOP_STR, fileStr); FileObject[] children = folder.getChildren(); assertEquals(2, children.length); assertEquals("/junit/folder/child1.txt", children[0].getName().getPath()); assertEquals("/junit/folder/child2.txt", children[1].getName().getPath()); child1.delete(); child2.delete(); folder.delete(); }
From source file:org.pentaho.s3.S3Test.java
@Test public void deleteBucket() throws Exception { assertNotNull("FileSystemManager is null", fsManager); FileObject bucket = fsManager.resolveFile(buildS3URL("/mdamour_delete_bucket_test")); assertEquals(false, bucket.exists()); bucket.createFolder();/*from www. j av a2s.c o m*/ assertEquals(true, bucket.exists()); bucket.delete(); assertEquals(false, bucket.exists()); }
From source file:org.saiku.web.rest.resources.BasicRepositoryResource.java
/** * Delete Query.//from www . j av a 2 s . c om * @param queryName - The name of the query. * @return A GONE Status if the query was deleted, otherwise it will return a NOT FOUND Status code. */ @DELETE @Produces({ "application/json" }) @Path("/{queryname}") public Status deleteQuery(@PathParam("queryname") String queryName) { try { if (repo != null) { if (!queryName.endsWith(".saiku")) { queryName += ".saiku"; } FileObject queryFile = repo.resolveFile(queryName); if (queryFile.delete()) { return (Status.GONE); } } throw new Exception("Cannot delete query file:" + queryName); } catch (Exception e) { log.error("Cannot delete query (" + queryName + ")", e); return (Status.NOT_FOUND); } }
From source file:org.sonatype.gshell.commands.vfs.EditCommand.java
public Object execute(final CommandContext context) throws Exception { assert context != null; FileObject file = resolveFile(context, path); new FileObjectAssert(file).exists().isReadable().isWritable(); // TODO: Add to FileObjectAssert ensureFileHasContent(file);/*from w w w .ja v a2s . com*/ FileObject tmp = file; // If the file is not on the local file system, then create tmp file for editing if (!getFileSystemAccess().isLocalFile(file)) { // Create a new temporary file, copy the contents for editing tmp = resolveFile(context, "tmp:/gshell-edit-" + System.currentTimeMillis() + ".txt"); log.debug("Using temporary file: {} ({})", tmp, tmp.getClass()); tmp.createFile(); tmp.copyFrom(file, Selectors.SELECT_SELF); } // Have to dereference the VFS file into a local file so the editor can access it File localFile = getFileSystemAccess().getLocalFile(tmp); Object result = edit(context, localFile); // If we had to use a tmp file for editing, then copy back and clean up if (tmp != file) { log.debug("Updating original file with edited content"); file.copyFrom(tmp, Selectors.SELECT_SELF); tmp.delete(); FileObjects.close(tmp); } FileObjects.close(file); return result; }
From source file:pt.webdetails.cpf.repository.vfs.VfsRepositoryAccess.java
public boolean removeFile(String file) { try {/*from w ww. j a va2 s .c o m*/ FileObject f = resolveFile(repo, file); if (f.exists()) { return f.delete(); } return true; } catch (Exception e) { throw new RuntimeException("Cannot delete file: " + file, e); } }
From source file:r.base.Files.java
private static void delete(FileObject file, boolean recursive) throws FileSystemException { if (file.exists()) { if (file.getType() == FileType.FILE) { file.delete(); } else if (file.getType() == FileType.FOLDER) { if (file.getChildren().length == 0) { file.delete();// w ww . j a v a 2 s .co m } else if (recursive) { file.delete(); } } } }