List of usage examples for org.apache.commons.vfs2 FileObject delete
int delete(FileSelector selector) throws FileSystemException;
From source file:org.jahia.modules.external.vfs.VFSDataSource.java
@Override public void removeItemByPath(String path) throws RepositoryException { try {/*from w w w . j a v a 2 s . co m*/ FileObject file = getFile(path); if (file.getType().hasChildren()) { file.delete(Selectors.SELECT_ALL); } else if (!file.delete()) { logger.warn("Failed to delete FileObject {}", getFile(path).toString()); } } catch (FileSystemException e) { throw new RepositoryException(e); } }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * This function deletes the given file. If the file object is a directory, all content and the directory itself will * be deleted.// w ww . j a v a 2 s. c om * * @param toDel * The file or directory to be deleted. * @return The number of deleted files. 0, if none has been deleted. */ public static int deleteFiles(final FileObject toDel) throws FileSystemException { if (FileType.FOLDER.equals(toDel.getType())) { /* Delete the directory. */ KalypsoCommonsDebug.DEBUG.printf("Deleting the directory %s ...%n", toDel.getName()); //$NON-NLS-1$ return toDel.delete(new AllFileSelector()); } else if (FileType.FILE.equals(toDel.getType())) { /* Delete the file. */ KalypsoCommonsDebug.DEBUG.printf("Deleting the file %s ...%n", toDel.getName()); //$NON-NLS-1$ if (toDel.delete()) return 1; KalypsoCommonsDebug.DEBUG.printf("Could not delete %s!%n", toDel.getName()); //$NON-NLS-1$ return 0; } else { /* The type of the file could not be determined, or it is an imaginary one. */ KalypsoCommonsDebug.DEBUG.printf("Could not delete %s!%n", toDel.getName()); //$NON-NLS-1$ return 0; } }
From source file:org.mycore.datamodel.ifs2.MCRStore.java
/** * Deletes the data stored in the given file object from the store * /*from w w w . ja va 2s.com*/ * @param fo * the file object to be deleted */ void delete(FileObject fo) throws IOException { FileObject parent = fo.getParent(); fo.delete(Selectors.SELECT_ALL); while (!parent.equals(baseDirectory)) { final FileObject[] children = parent.getChildren(); if (children.length > 0) { break; } fo = parent; parent = fo.getParent(); fo.delete(); } }
From source file:org.ow2.proactive.scheduler.smartproxy.JobTrackerImpl.java
/** * Removes from the proxy knowledge all info related with the given job. * This will also delete every folder created by the job in the shared input and output spaces * * @param id jobID// w w w .j a va 2 s . c om */ public void removeAwaitedJob(String id) { AwaitedJob aj = jobDatabase.getAwaitedJob(id); if (aj == null) { logger.warn("Job " + id + " not in the awaited list"); return; } logger.debug("Removing knowledge of job " + id); String pullUrl = aj.getPullURL(); String pushUrl = aj.getPushURL(); FileObject remotePullFolder = null; FileObject remotePushFolder = null; try { remotePullFolder = resolveFile(pullUrl); remotePushFolder = resolveFile(pushUrl); } catch (Exception e) { logger.error("Could not remove data for job " + id, e); return; } if (aj.isIsolateTaskOutputs()) { try { remotePullFolder = remotePullFolder.getParent(); } catch (FileSystemException e) { logger.error("Could not get the parent of folder " + remotePullFolder, e); } } Set<FileObject> foldersToDelete = new HashSet<>(); try { foldersToDelete.add(remotePullFolder.getParent()); if (!remotePullFolder.getParent().equals(remotePushFolder.getParent())) foldersToDelete.add(remotePushFolder.getParent()); } catch (FileSystemException e) { logger.warn("Data in folders " + pullUrl + " and " + pushUrl + " cannot be deleted due to an unexpected error ", e); } String url = "NOT YET DEFINED"; for (FileObject fo : foldersToDelete) { try { url = fo.getURL().toString(); if (!logger.isTraceEnabled()) { logger.debug("Deleting directory " + url); fo.delete(Selectors.SELECT_ALL); fo.delete(); } } catch (FileSystemException e) { logger.warn("Could not delete temporary files at location " + url + " .", e); } } jobDatabase.removeAwaitedJob(id); try { jobDatabase.commit(); } catch (IOException e) { logger.error("Could not save status file after removing job " + id, e); } }
From source file:org.ow2.proactive.scheduler.smartproxy.JobTrackerImpl.java
/** * Removes from the proxy knowledge all info related with the given task. * If all tasks of a job have been removed this way, the job itself will be removed. * * @param id jobID// ww w . j a va 2 s .com * @param taskName task name */ public void removeAwaitedTask(String id, String taskName) { AwaitedJob awaitedJob = jobDatabase.getAwaitedJob(id); if (awaitedJob == null) { logger.warn("Job " + id + " not in the awaited list"); return; } AwaitedTask awaitedTask = awaitedJob.getAwaitedTask(taskName); if (awaitedTask == null) { logger.warn("Task " + taskName + " from Job " + id + " not in the awaited list"); return; } logger.debug("Removing knowledge of task " + taskName + " from job " + id); if (awaitedJob.isIsolateTaskOutputs() && awaitedTask.getTaskId() != null) { // If the output data as been isolated in a dedicated folder we can delete it. String pullUrl = awaitedJob.getPullURL(); pullUrl = pullUrl.replace(SchedulerConstants.TASKID_DIR_DEFAULT_NAME, SchedulerConstants.TASKID_DIR_DEFAULT_NAME + "/" + awaitedTask.getTaskId()); FileObject remotePullFolder = null; try { remotePullFolder = resolveFile(pullUrl); logger.debug("Deleting directory " + remotePullFolder); remotePullFolder.delete(Selectors.SELECT_ALL); remotePullFolder.delete(); } catch (Exception e) { logger.warn("Could not remove data for task " + taskName + " of job " + id, e); } } awaitedJob.removeAwaitedTask(taskName); if (awaitedJob.getAwaitedTasks().isEmpty()) { removeAwaitedJob(id); return; } else { // this is done to ensure persistence of the operation jobDatabase.putAwaitedJob(id, awaitedJob); } try { jobDatabase.commit(); } catch (IOException e) { logger.error("Could not save status file after removing task Task " + taskName + " from Job" + id, e); } }
From source file:org.ow2.proactive.scheduler.smartproxy.SmartProxyImpl.java
@Override protected void removeJobIO(Job job, String pushURL, String pullURL, String newFolderName) { pushURL = pushURL + "/" + newFolderName; FileObject fo; try {// w w w.java 2s . c o m fo = jobTracker.resolveFile(pushURL); fo.delete(Selectors.SELECT_ALL); fo.delete(); } catch (Exception e) { log.error("Error in removeJobIO push for job " + job.getName(), e); } pullURL = pullURL + "/" + newFolderName; try { fo = jobTracker.resolveFile(pullURL); fo.delete(Selectors.SELECT_ALL); fo.delete(); } catch (Exception e) { log.error("Error in removeJobIO pull for job " + job.getName(), e); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.RestDataspaceImpl.java
private Response deleteDir(FileObject fo, List<String> includes, List<String> excludes) throws FileSystemException { if ((includes == null || includes.isEmpty()) && (excludes == null || excludes.isEmpty())) { fo.delete(SELECT_ALL); fo.delete();//from ww w.j a v a2 s. c o m return noContentRes(); } else { List<FileObject> children = FileSystem.findFiles(fo, includes, excludes); for (FileObject child : children) { if (!child.delete()) { child.delete(SELECT_ALL); child.delete(); } } return noContentRes(); } }
From source file:org.ow2.proactive_grid_cloud_portal.dataspace.RestDataspaceImpl.java
public void writeFile(InputStream inputStream, FileObject outputFile, String encoding) throws FileSystemException, IOException { try {//from w w w . j av a2 s . c o m if (outputFile.exists()) { outputFile.delete(SELECT_SELF); } if (Strings.isNullOrEmpty(encoding)) { outputFile.createFile(); FileSystem.copy(inputStream, outputFile); } else if ("gzip".equals(encoding)) { VFSZipper.GZIP.unzip(inputStream, outputFile); } else if ("zip".equals(encoding)) { VFSZipper.ZIP.unzip(inputStream, outputFile); } else { outputFile.createFile(); FileSystem.copy(inputStream, outputFile); } } catch (Throwable error) { if (outputFile != null) { try { if (outputFile.exists()) { outputFile.delete(SELECT_SELF); } } catch (FileSystemException e1) { logger.error("Error occurred while deleting partially created file.", e1); } } Throwables.propagateIfInstanceOf(error, FileSystemException.class); Throwables.propagateIfInstanceOf(error, IOException.class); Throwables.propagate(error); } }
From source file:org.pentaho.di.job.entries.hadoopjobexecutor.JarUtilityTest.java
@BeforeClass public static void setup() throws Exception { FileObject testPath = VFS.getManager().resolveFile(TEST_PATH); testPath.delete(new AllFileSelector()); testPath.createFolder();/*www. j av a2 s . co m*/ }
From source file:org.pentaho.hadoop.shim.common.DistributedCacheUtilImpl.java
/** * Delete a directory and all of its contents * * @param dir Directory to delete//from w w w. j a v a 2 s. co m * @return True if the directory was deleted successfully */ public boolean deleteDirectory(FileObject dir) throws FileSystemException { dir.delete(new AllFileSelector()); return !dir.exists(); }