List of usage examples for org.apache.commons.io FileDeleteStrategy FORCE
FileDeleteStrategy FORCE
To view the source code for org.apache.commons.io FileDeleteStrategy FORCE.
Click Source Link
From source file:my.FileDeleteStrategyTestCase.java
public void testDeleteForce() throws Exception { File baseDir = getTestDirectory(); File subDir = new File(baseDir, "test"); assertEquals(true, subDir.mkdir());/*w ww . jav a 2 s . com*/ File subFile = new File(subDir, "a.txt"); createFile(subFile, 16); assertEquals(true, subDir.exists()); assertEquals(true, subFile.exists()); // delete dir FileDeleteStrategy.FORCE.delete(subDir); assertEquals(false, subDir.exists()); assertEquals(false, subFile.exists()); // delete dir FileDeleteStrategy.FORCE.delete(subDir); // no error assertEquals(false, subDir.exists()); }
From source file:com.adaptris.core.runtime.MessageDigestErrorEntryTest.java
private File deleteLater(Object marker) throws IOException { File f = File.createTempFile(this.getClass().getSimpleName(), ""); f.deleteOnExit();/*from w w w . j ava 2 s. com*/ cleaner.track(f, marker, FileDeleteStrategy.FORCE); return f; }
From source file:com.adaptris.core.lms.LargeFsConsumer.java
@Override protected int processFile(File originalFile) throws CoreException { int rc = 0;/*from w w w.j av a2s . c o m*/ try { if (originalFile.getName().endsWith(getWipSuffix())) { log.debug("ignoring part-processed file [{}]", originalFile.getName()); } else { if (checkModified(originalFile) && isFileAccessible(originalFile)) { File wipFile = renameFile(originalFile); AdaptrisMessage msg = decode(wipFile); addStandardMetadata(msg, originalFile, wipFile); retrieveAdaptrisMessageListener().onAdaptrisMessage(msg); rc++; tracker.track(wipFile, msg, FileDeleteStrategy.FORCE); } else { log.trace("{} not deemed safe to process", originalFile.getName()); } } } catch (FsException | IOException e) { throw new CoreException(e); } return rc; }
From source file:my.FileDeleteStrategyTestCase.java
public void testToString() { assertEquals("FileDeleteStrategy[Normal]", FileDeleteStrategy.NORMAL.toString()); assertEquals("FileDeleteStrategy[Force]", FileDeleteStrategy.FORCE.toString()); }
From source file:com.persistent.util.WAStartUp.java
@Override public void earlyStartup() { try {/*from w ww . ja va 2s. c o m*/ //Make schema entries in XML Catalog makeXMLCatalogEntry(); //Add resourceChangeListener to listen to changes of resources WAResourceChangeListener listener = new WAResourceChangeListener(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); workspace.addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); IWorkspaceRoot root = workspace.getRoot(); PreferenceUtilStrg.load(); //Get all the projects in workspace IProject[] projects = root.getProjects(); for (IProject iProject : projects) { Activator.getDefault().log(iProject.getName() + "isOpen" + iProject.isOpen(), null); if (iProject.isOpen()) { boolean isNature = iProject.hasNature(Messages.stUpProjNature); Activator.getDefault().log(iProject.getName() + "isNature" + isNature, null); if (isNature) { WindowsAzureProjectManager projMngr = WindowsAzureProjectManager .load(iProject.getLocation().toFile()); if (!projMngr.isCurrVersion()) { WAEclipseHelper.handleProjectUpgrade(iProject, projMngr); } // Correct name if its invalid if (!iProject.getName().equalsIgnoreCase(projMngr.getProjectName())) { WAEclipseHelper.correctProjectName(iProject, projMngr); } projMngr = initializeStorageAccountRegistry(projMngr); projMngr = changeLocalToAuto(projMngr, iProject.getName()); // save object so that access key will get saved in PML. projMngr.save(); } } } // save preference file. PreferenceUtilStrg.save(); //this code is for copying componentset.xml in plugins folder copyPluginComponents(); // refresh workspace as package.xml may have got changed. WAEclipseHelper.refreshWorkspace(Messages.resCLJobName, Messages.resCLExWkspRfrsh); // delete %proj% directory from temporary folder during eclipse start String tmpPath = System.getProperty("java.io.tmpdir"); String projPath = String.format("%s%s%s", tmpPath, File.separator, "%proj%"); File projFile = new File(projPath); if (projFile != null) { FileDeleteStrategy.FORCE.delete(projFile); } } catch (Exception e) { /* This is not a user initiated task So user should not get any exception prompt.*/ Activator.getDefault().log(Messages.expErlStrtUp, e); } }
From source file:com.adaptris.core.lms.FileBackedMessageFactory.java
private File createTempFile(File tempDir, Object marker) throws IOException { File f = File.createTempFile(TMP_FILE_PREFIX, TMP_FILE_SUFFIX, tempDir); cleaner.track(f, Args.notNull(marker, "marker"), FileDeleteStrategy.FORCE); return f;/*from www . jav a 2 s .c o m*/ }
From source file:com.xandrev.jdorg.main.ExecutorService.java
private void applyOrganizers(File initialFolder) { ArrayList<String> list = new ArrayList<String>(); for (Organizer org : organizerList) { logger.info("Organizer: " + org.getClass().toString()); Collection<File> fileList = org.getFiles(initialFolder); if (fileList != null) { for (File fd : fileList) { String folder = org.generateFolder(fd.getName()); if (folder != null && !list.contains(fd.getAbsolutePath())) { list.add(fd.getAbsolutePath()); logger.info("Folder: " + folder); logger.info("Root Folder: " + folder); String finalPath = finalDirectory + File.separator + folder; File dirPath = new File(finalPath); logger.info("Final Path: " + finalPath); if (!dirPath.exists()) { boolean result = dirPath.mkdirs(); logger.debug("Resultado de la creacion de directorios: " + result); }/*from w w w . j a va2 s .c o m*/ File finalFile = new File(finalPath + File.separator + fd.getName()); if (!finalFile.exists()) { try { logger.info("Final path not exist. Copying the file at: " + finalFile.getAbsolutePath()); String origPath = fd.getAbsolutePath(); String origHash = calculateHash(fd); logger.debug("Original hash: " + origHash); boolean renamed = fd.renameTo(finalFile); boolean deleted = false; boolean copied = false; logger.info("Renamed attempt result successfully: " + renamed); if (!renamed) { logger.info("Trying to copy the file to: " + finalFile.getAbsolutePath()); FileUtils.copyFile(fd, finalFile); copied = finalFile.exists(); if (copied) { String finalHash = calculateHash(finalFile); logger.debug("Final hash: " + finalHash); if (origHash != null && origHash.equals(finalHash)) { deleted = fd.delete(); logger.info("Copy finished: " + finalFile.getAbsolutePath()); } else { logger.info("Copy finisehd with error because hash are not equals"); finalFile.delete(); } } } logger.info(i18n.getLocalizerText("file.rename.1") + fd.getAbsolutePath() + i18n.getLocalizerText("file.rename.2") + finalFile.getAbsolutePath()); logger.info("Starting to audit the file organized"); org.audit(auditService, origPath, finalPath, renamed, copied, deleted); logger.info("Audit the file organized completed"); } catch (IOException ex) { logger.error(ex); } } if (!fd.delete()) { try { FileDeleteStrategy.FORCE.delete(fd); } catch (IOException e) { logger.error(e); } } } } } } }
From source file:com.adaptris.core.ftp.SftpKeyAuthConnectionTest.java
private File copyHostsFile(File srcKnownHosts) throws Exception { File tempDir = new File(PROPERTIES.getProperty(CFG_TEMP_HOSTS_FILE)); if (!tempDir.exists() && !tempDir.mkdirs()) { throw new Exception("Couldn't make directory " + tempDir.getCanonicalPath()); }//from w w w . j a va2s . c o m File tempFile = File.createTempFile(SftpKeyAuthConnectionTest.class.getSimpleName(), "", tempDir); FileUtils.copyFile(srcKnownHosts, tempFile); tempFile.deleteOnExit(); cleaner.track(tempFile, fileTracker, FileDeleteStrategy.FORCE); return tempFile; }
From source file:com.adaptris.core.ftp.StandardSftpConnectionTest.java
private File copyHostsFile(File srcKnownHosts) throws Exception { File tempDir = new File(PROPERTIES.getProperty(CFG_TEMP_HOSTS_FILE)); if (!tempDir.exists() && !tempDir.mkdirs()) { throw new Exception("Couldn't make directory " + tempDir.getCanonicalPath()); }/*from ww w . j a va 2s .c o m*/ File tempFile = File.createTempFile(StandardSftpConnectionTest.class.getSimpleName(), "", tempDir); FileUtils.copyFile(srcKnownHosts, tempFile); tempFile.deleteOnExit(); cleaner.track(tempFile, fileTracker, FileDeleteStrategy.FORCE); return tempFile; }
From source file:com.hp.test.framework.generatejellytess.GenerateJellyTests.java
public static void CreateJellyTestsFolder(String path, boolean CleanFiles, String Feature_name) { File f = new File(path); if (!f.exists()) { log.info("Jelly Testcase Output path not exits"); return;/*from w w w . jav a 2 s . co m*/ } f = new File(path + Feature_name); if (f.exists() && !CleanFiles) { log.info("Path already exists; Jelly Tests will be overridden"); return; } if (f.exists() && CleanFiles) { try { for (File file : f.listFiles()) { FileDeleteStrategy.FORCE.delete(file); } log.info("Cleaned all the files in the location" + path); } catch (IOException e) { log.error("Exception in cleaning files" + e.getMessage()); } log.info("Cleaned previously generated files properly"); } else { try { f.mkdirs(); } catch (Exception e) { log.error("Exception in creating Directory" + e.getMessage()); } log.info("Direcory Created " + f.getAbsolutePath()); } }