List of usage examples for org.apache.commons.io FileUtils cleanDirectory
public static void cleanDirectory(File directory) throws IOException
From source file:BluemixUtils.java
private static void clearTempDir() throws IOException { if (!new File(TMP_DIR).exists()) { System.out.println("Create temp directory"); new File(TMP_DIR).mkdir(); }// w ww . jav a 2 s . com System.out.println("Clear tmp dir"); FileUtils.cleanDirectory(new File(TMP_DIR)); }
From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java
/** {@inheritDoc} */ protected void setUp() throws Exception { super.setUp(); FileUtils.forceMkdir(TARGETDIR);/*from w ww .j a va 2 s .c o m*/ if (CLEANTARGETDIRECTORYBEFORERUN) { FileUtils.cleanDirectory(TARGETDIR); } }
From source file:de.thischwa.pmcms.view.renderer.ExportRenderer.java
public void init() { try {/*from www.j a va2 s . co m*/ if (!this.exportDir.exists()) this.exportDir.mkdirs(); else FileUtils.cleanDirectory(this.exportDir); } catch (IOException e) { throw new RuntimeException("While checking/cleaning the export path:" + e.getMessage(), e); } // collect renderable / validation renderableObjects = PoInfo.collectRenderables(site, messages); exportController = new ExportThreadPoolController(maxThreadsPerCount); logger.info("Site successfully exported."); }
From source file:com.funambol.server.cleanup.ClientLogCleanUpAgentTest.java
@Override protected void tearDown() throws Exception { super.tearDown(); FileUtils.cleanDirectory(new File(TARGET_DIR)); }
From source file:eu.planets_project.services.utils.ZipUtilsTest.java
/** * Test method for {@link eu.planets_project.services.utils.ZipUtils#removeFileFrom(java.io.File, java.lang.String)}. * @throws IOException // w w w. jav a 2 s . co m */ @Test public void testRemoveFile() throws IOException { FileUtils.cleanDirectory(outputFolder); ZipUtils.listAllFilesAndFolders(TEST_FILE_FOLDER, new ArrayList<File>()).size(); File zip = ZipUtils.createZip(TEST_FILE_FOLDER, outputFolder, "zipUtilsTestRemove.zip", true); System.out.println("Zip created. Please find it here: " + zip.getAbsolutePath()); String folderName = zip.getName().substring(0, zip.getName().lastIndexOf(".")); File extract = new File(outputFolder, folderName); FileUtils.forceMkdir(extract); ZipUtils.unzipTo(zip, extract); new File(PROJECT_BASE_FOLDER, "src/test/data/test_zip/docs/lorem-ipsum.txt"); // File deleteSingleFile = new File("IF/common/src/test/resources/test_zip/images/test_jp2/canon-ixus.jpg.jp2"); ZipUtils.removeFileFrom(zip, "docs/lorem-ipsum.txt"); ZipUtils.removeFileFrom(zip, "docs"); System.out.println("Zip modified. Please find it here: " + zip.getAbsolutePath()); }
From source file:com.linwoodhomes.internal.DefaultTempFile.java
/** * Create a new file factory so that the previous instance will be garbage * collected and it's temporary files deleted. * /* ww w. j a v a2s .c o m*/ * Lets try to use the temp cleaning tracker ourselves. * @throws InitializationException if the file factory could not init. */ private void resetFileFactory() throws InitializationException { File xwikiTmpDir = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + "xwiki-tmp"); log.info("DefaultTempFile: Setting temp file location to: " + xwikiTmpDir); try { if (xwikiTmpDir.exists() && xwikiTmpDir.isDirectory()) { // clean out any existing temporary files. FileUtils.cleanDirectory(xwikiTmpDir); log.debug("DefaultTempFile: cleaned up temporary directory"); } else { // create the directory xwikiTmpDir.mkdir(); } log.info("DefaultTempFile: Files will be created in memory with" + " fileSize LESS than: " + DEFAULT_SIZE_THRESHOLD + " bytes. Files >= will be saved to disk."); fileFactory = new DiskFileItemFactory(DEFAULT_SIZE_THRESHOLD, xwikiTmpDir); fileFactory.setFileCleaningTracker(null); // let us handle the // tracking. } catch (IOException ioe) { log.error("Failed to initialize the temp file factory in directory: " + xwikiTmpDir, ioe); throw new InitializationException("Could not initialize temporary File Factory", ioe); } }
From source file:com.seleniumtests.ut.util.squashta.TestTaScriptGenerator.java
/** * Test if files which are no more valid are deleted * @throws IOException/*w w w .j a v a 2 s. co m*/ */ @Test(groups = { "squash" }) public void testCleanGeneratedFiles() throws IOException { File tmpFolder = Paths.get(SeleniumTestsContextManager.getDataPath(), "tmp").toFile(); tmpFolder.mkdirs(); FileUtils.write(Paths.get(tmpFolder.getPath(), "a_file.ta").toFile(), ""); FileUtils.write(Paths.get(tmpFolder.getPath(), "g__a_file.ta").toFile(), ""); FileUtils.write(Paths.get(tmpFolder.getPath(), "g__an_other_file.ta").toFile(), ""); TaScriptGenerator scriptGenerator = new TaScriptGenerator("core", SeleniumTestsContextManager.getRootPath(), SeleniumTestsContextManager.getRootPath()); try { scriptGenerator.cleanGeneratedFile(tmpFolder.toString(), Arrays.asList("g__a_file.ta", "g__a_file2.ta")); Assert.assertFalse(Paths.get(tmpFolder.getPath(), "g__an_other_file.ta").toFile().exists(), "g__an_other_file.ta should have been deleted"); Assert.assertTrue(Paths.get(tmpFolder.getPath(), "g__a_file.ta").toFile().exists(), "g__an_other_file.ta should not have been deleted"); Assert.assertTrue(Paths.get(tmpFolder.getPath(), "a_file.ta").toFile().exists(), "g__an_other_file.ta should not have been deleted"); } finally { FileUtils.cleanDirectory(tmpFolder); tmpFolder.delete(); } }
From source file:com.bibisco.test.AllTests.java
@BeforeClass public static void cleanProjectsDirectory() throws IOException, ConfigurationException, InterruptedException { FileUtils.copyFile(new File(mStrTestBibiscoDBFilePath), new File(mStrDBFilePath)); FileUtils.cleanDirectory(new File(BIBISCO_INTERNAL_PROJECTS_DIR)); FileUtils.copyDirectoryToDirectory(new File(mStrTestProjectDBFilePath), new File(BIBISCO_INTERNAL_PROJECTS_DIR)); FileUtils.copyDirectoryToDirectory(new File(mStrTestProject2DBFilePath), new File(BIBISCO_INTERNAL_PROJECTS_DIR)); FileUtils.copyDirectoryToDirectory(new File(mStrTestProject3DBFilePath), new File(BIBISCO_INTERNAL_PROJECTS_DIR)); }
From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java
/** {@inheritDoc} */ protected void tearDown() throws Exception { super.tearDown(); if (CLEANTARGETDIRECTORYAFTERRUN) { FileUtils.cleanDirectory(TARGETDIR); }/* w w w . jav a 2 s .c om*/ }
From source file:aurelienribon.gdxsetupui.ProjectSetup.java
/** * The raw structure of all projects is contained in a zip file. This * method inflates this file in a temporary folder. * @throws IOException//from w w w.j a va2 s .c om */ public void inflateProjects() throws IOException { FileUtils.forceMkdir(tmpDst); FileUtils.cleanDirectory(tmpDst); InputStream is = Res.getStream("projects.zip"); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { File file = new File(tmpDst, entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(file); } else { OutputStream os = new FileOutputStream(file); IOUtils.copy(zis, os); os.close(); } } zis.close(); }