Java Code Examples for org.apache.commons.vfs2.FileObject#deleteAll()
The following examples show how to use
org.apache.commons.vfs2.FileObject#deleteAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VFSNotebookRepo.java From zeppelin with Apache License 2.0 | 5 votes |
@Override public void remove(String folderPath, AuthenticationInfo subject) throws IOException { LOGGER.info("Remove folder: " + folderPath); FileObject folderObject = rootNotebookFileObject.resolveFile( folderPath.substring(1), NameScope.DESCENDENT); folderObject.deleteAll(); }
Example 2
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Copies another file to this file. * * @param file The FileObject to copy. * @param selector The FileSelector. * @throws FileSystemException if an error occurs. */ @Override public void copyFrom(final FileObject file, final FileSelector selector) throws FileSystemException { if (!FileObjectUtils.exists(file)) { throw new FileSystemException("vfs.provider/copy-missing-file.error", file); } // Locate the files to copy across final ArrayList<FileObject> files = new ArrayList<>(); file.findFiles(selector, false, files); // Copy everything across for (final FileObject srcFile : files) { // Determine the destination file final String relPath = file.getName().getRelativeName(srcFile.getName()); final FileObject destFile = resolveFile(relPath, NameScope.DESCENDENT_OR_SELF); // Clean up the destination file, if necessary if (FileObjectUtils.exists(destFile) && destFile.getType() != srcFile.getType()) { // The destination file exists, and is not of the same type, // so delete it // TODO - add a pluggable policy for deleting and overwriting existing files destFile.deleteAll(); } // Copy across try { if (srcFile.getType().hasContent()) { FileObjectUtils.writeContent(srcFile, destFile); } else if (srcFile.getType().hasChildren()) { destFile.createFolder(); } } catch (final IOException e) { throw new FileSystemException("vfs.provider/copy-file.error", e, srcFile, destFile); } } }
Example 3
Source File: DefaultFileReplicator.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Physically deletes the file from the file system. * * @param file The File to delete. */ protected void deleteFile(final File file) { try { final FileObject fileObject = getContext().toFileObject(file); fileObject.deleteAll(); } catch (final FileSystemException e) { final String message = Messages.getString("vfs.impl/delete-temp.warn", file.getName()); VfsLog.warn(getLogger(), log, message, e); } }
Example 4
Source File: SharedObjectsTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testCopyBackupVfs() throws Exception { final String dirName = "ram:/SharedObjectsTest"; FileObject baseDir = KettleVFS.getFileObject( dirName ); try { baseDir.createFolder(); final String fileName = dirName + "/shared.xml"; SharedObjects sharedObjects = new SharedObjects( fileName ); SharedObjectInterface shared1 = new TestSharedObject( "shared1", "<shared1>shared1</shared1>" ); sharedObjects.storeObject( shared1 ); sharedObjects.saveToFile(); final String backupFileName = fileName + ".backup"; FileObject backup = KettleVFS.getFileObject( backupFileName ); Assert.assertFalse( backup.exists() ); String contents = KettleVFS.getTextFileContent( fileName, "utf8" ); Assert.assertTrue( contents.contains( shared1.getXML() ) ); SharedObjectInterface shared2 = new TestSharedObject( "shared2", "<shared2>shared2</shared2>" ); sharedObjects.storeObject( shared2 ); sharedObjects.saveToFile(); Assert.assertTrue( backup.exists() ); String contentsBackup = KettleVFS.getTextFileContent( backupFileName, "utf8" ); Assert.assertEquals( contents, contentsBackup ); } finally { if ( baseDir.exists() ) { baseDir.deleteAll(); } } }
Example 5
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Moves (rename) the file to another one. * * @param destFile The target FileObject. * @throws FileSystemException if an error occurs. */ @Override public void moveTo(final FileObject destFile) throws FileSystemException { if (canRenameTo(destFile)) { if (!getParent().isWriteable()) { throw new FileSystemException("vfs.provider/rename-parent-read-only.error", getName(), getParent().getName()); } } else { if (!isWriteable()) { throw new FileSystemException("vfs.provider/rename-read-only.error", getName()); } } if (destFile.exists() && !isSameFile(destFile)) { destFile.deleteAll(); // throw new FileSystemException("vfs.provider/rename-dest-exists.error", destFile.getName()); } if (canRenameTo(destFile)) { // issue rename on same filesystem try { attach(); // remember type to avoid attach final FileType srcType = getType(); doRename(destFile); FileObjectUtils.getAbstractFileObject(destFile).handleCreate(srcType); destFile.close(); // now the destFile is no longer imaginary. force reattach. handleDelete(); // fire delete-events. This file-object (src) is like deleted. } catch (final RuntimeException re) { throw re; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/rename.error", exc, getName(), destFile.getName()); } } else { // different fs - do the copy/delete stuff destFile.copyFrom(this, Selectors.SELECT_SELF); if ((destFile.getType().hasContent() && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE) || destFile.getType().hasChildren() && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER)) && fileSystem.hasCapability(Capability.GET_LAST_MODIFIED)) { destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime()); } deleteSelf(); } }
Example 6
Source File: ProviderWriteTests.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Tests deletion */ public void testDelete() throws Exception { // Set-up the test structure final FileObject folder = createScratchFolder(); folder.resolveFile("file1.txt").createFile(); folder.resolveFile("file%25.txt").createFile(); folder.resolveFile("emptydir").createFolder(); folder.resolveFile("dir1/file1.txt").createFile(); folder.resolveFile("dir1/dir2/file2.txt").createFile(); // Delete a file FileObject file = folder.resolveFile("file1.txt"); assertTrue(file.exists()); file.deleteAll(); assertFalse(file.exists()); // Delete a special name file file = folder.resolveFile("file%25.txt"); assertTrue(file.exists()); file.deleteAll(); assertFalse(file.exists()); // Delete an empty folder file = folder.resolveFile("emptydir"); assertTrue(file.exists()); file.deleteAll(); assertFalse(file.exists()); // Recursive delete file = folder.resolveFile("dir1"); final FileObject file2 = file.resolveFile("dir2/file2.txt"); assertTrue(file.exists()); assertTrue(file2.exists()); file.deleteAll(); assertFalse(file.exists()); assertFalse(file2.exists()); // Delete a file that does not exist file = folder.resolveFile("some-folder/some-file"); assertFalse(file.exists()); file.deleteAll(); assertFalse(file.exists()); }
Example 7
Source File: ProviderWriteTests.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Tests deletion */ public void testDeleteAllDescendents() throws Exception { // Set-up the test structure final FileObject folder = createScratchFolder(); folder.resolveFile("file1.txt").createFile(); folder.resolveFile("file%25.txt").createFile(); folder.resolveFile("emptydir").createFolder(); folder.resolveFile("dir1/file1.txt").createFile(); folder.resolveFile("dir1/dir2/file2.txt").createFile(); // Delete a file FileObject file = folder.resolveFile("file1.txt"); assertTrue(file.exists()); file.deleteAll(); assertFalse(file.exists()); // Delete a special name file file = folder.resolveFile("file%25.txt"); assertTrue(file.exists()); file.deleteAll(); assertFalse(file.exists()); // Delete an empty folder file = folder.resolveFile("emptydir"); assertTrue(file.exists()); file.deleteAll(); assertFalse(file.exists()); // Recursive delete file = folder.resolveFile("dir1"); final FileObject file2 = file.resolveFile("dir2/file2.txt"); assertTrue(file.exists()); assertTrue(file2.exists()); file.deleteAll(); assertFalse(file.exists()); assertFalse(file2.exists()); // Delete a file that does not exist file = folder.resolveFile("some-folder/some-file"); assertFalse(file.exists()); file.deleteAll(); assertFalse(file.exists()); }
Example 8
Source File: ProviderWriteTests.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Test that children are handled correctly by create and delete. */ public void testListChildren() throws Exception { final FileObject folder = createScratchFolder(); final HashSet<String> names = new HashSet<>(); // Make sure the folder is empty assertEquals(0, folder.getChildren().length); // Create a child folder folder.resolveFile("dir1").createFolder(); names.add("dir1"); assertSameFileSet(names, folder.getChildren()); // Create a child file folder.resolveFile("file1.html").createFile(); names.add("file1.html"); assertSameFileSet(names, folder.getChildren()); // Create a descendent folder.resolveFile("dir2/file1.txt").createFile(); names.add("dir2"); assertSameFileSet(names, folder.getChildren()); // Create a child file via an output stream final OutputStream outstr = folder.resolveFile("file2.txt").getContent().getOutputStream(); outstr.close(); names.add("file2.txt"); assertSameFileSet(names, folder.getChildren()); // Delete a child folder folder.resolveFile("dir1").deleteAll(); names.remove("dir1"); assertSameFileSet(names, folder.getChildren()); // Delete a child file folder.resolveFile("file1.html").deleteAll(); names.remove("file1.html"); assertSameFileSet(names, folder.getChildren()); // Recreate the folder folder.deleteAll(); folder.createFolder(); assertEquals(0, folder.getChildren().length); }