List of usage examples for org.apache.commons.io FileUtils deleteDirectory
public static void deleteDirectory(File directory) throws IOException
From source file:com.msopentech.thali.utilities.android.AndroidXmlHttpRequestTestActivity.java
private void loadManifestFilesIntoDirectory(String resourceDirectoryPath) throws IOException { File directoryAtDestination = new File(getFilesDir(), resourceDirectoryPath); if (directoryAtDestination.exists()) { FileUtils.deleteDirectory(directoryAtDestination); }// www .j av a 2 s . co m if (directoryAtDestination.mkdirs() == false) { throw new RuntimeException("Couldn't create destination!"); } final String manifestFileName = "manifest.csv"; String[] files = IOUtils.toString(getClass().getResourceAsStream(resourceDirectoryPath + manifestFileName)) .split(","); for (String fileName : files) { readResourceIntoDirectory(resourceDirectoryPath + fileName); } }
From source file:blocks.CreateJavaFiles.java
/** * Creates a directory with the same name as the model for all the relevant * files; if the directory already exists, then deletes the directory and * all the files within it before re-creating the directory. (neha) *//*from w w w .jav a 2 s . com*/ public void createDirectory() { try { File directory = new File(destination + modelName); // neha: 10/09/2015 if the directory already exists, delete it first // Java isn't able to delete folders with data in it; so rather than // write a recursive method, this is done with FileUtils in // the Apache Commons IO library. if (directory.exists()) { FileUtils.deleteDirectory(directory); // directory.delete(); } // Makes a directory, including any necessary but nonexistent // parent directories. FileUtils.forceMkdir(directory); System.out.println("Directory: " + destination + modelName + " created"); } catch (Exception e) { // Catch exception if any System.err.println("Error creating directory: " + destination + modelName + ": " + e.getMessage()); } }
From source file:info.magnolia.ui.framework.command.CleanTempFilesCommandTest.java
@After public void tearDown() throws Exception { FileUtils.deleteDirectory(tmpDir); }
From source file:com.xiaomi.linden.server.TestLindenServer.java
@BeforeClass public static void init() { try {/*from w ww . j a v a 2s.co m*/ FileUtils.deleteDirectory(new File("./target/linden_server_data")); ZooKeeperService.start(); startLindenServer(); index(); server1.refresh(); server2.refresh(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ezbake.frack.submitter.util.UnzipUtilTest.java
@Test public void testUnzip() throws IOException { File unzipped = null;/*from w ww . j a v a2 s . c o m*/ try { InputStream is = getClass().getResourceAsStream("/example.tar.gz"); byte[] tarGzBytes = IOUtils.toByteArray(is); is.close(); unzipped = UnzipUtil.unzip(new File(System.getProperty("user.dir")), ByteBuffer.wrap(tarGzBytes)); assertTrue("Unzipped folder exists", unzipped.exists()); assertTrue("Unzipped folder is a folder", unzipped.isDirectory()); Optional<String> jarPath = UnzipUtil.getJarPath(unzipped); assertTrue("Jar path exists", jarPath.isPresent()); File jarFile = new File(jarPath.get()); assertEquals("Jar path has correct name", "example.jar", jarFile.getName()); assertEquals("Jar has correct parent", "bin", jarFile.getParentFile().getName()); Optional<String> confPath = UnzipUtil.getConfDirectory(unzipped); assertTrue("Conf path exists", confPath.isPresent()); File confDir = new File(confPath.get()); Optional<String> sslPath = UnzipUtil.getSSLPath(confDir); assertTrue("SSL path exists", sslPath.isPresent()); File keyPath = UnzipUtil.findSubDir(confDir, "keys"); assertTrue("Keys path exists", keyPath.exists()); } finally { if (unzipped != null && unzipped.exists()) { FileUtils.deleteDirectory(unzipped); } } }
From source file:ch.vorburger.mariadb4j.StartSimulatedForAllPlatformsTest.java
void checkPlatformStart(String platform) throws ManagedProcessException, IOException { DBConfigurationBuilder configBuilder = DBConfigurationBuilder.newBuilder(); configBuilder.setOS(platform);/*www. j av a 2 s . c o m*/ DBConfiguration config = configBuilder.build(); DB db = new DB(config); db.prepareDirectories(); db.unpackEmbeddedDb(); ManagedProcess installProc = db.installPreparation(); checkManagedProcessExists(installProc); ManagedProcess startProc = db.startPreparation(); checkManagedProcessExists(startProc); // This is super important.. without this, the test is useless, // as it will not catch platform specific problems, because the files // from previous platform test will still be available FileUtils.deleteDirectory(new File(config.getBaseDir())); }
From source file:com.magnet.tools.tests.MagnetToolStepDefs.java
public static void installMagnetZip(String filePath, String directory, boolean cleanFirst) throws Throwable { String file = expandVariables(filePath).trim(); Assert.assertTrue("installer zip should exist:" + file, new File(file).exists()); Assert.assertTrue("installer zip should be a file:" + file, new File(file).isFile()); Assert.assertTrue("installer zip path must be absolute:" + file, new File(file).isAbsolute()); File dir = new File(expandVariables(directory).trim()); if (cleanFirst) { if (dir.exists()) { FileUtils.deleteDirectory(dir); }/*from w ww.ja va 2 s . c o m*/ if (!dir.mkdirs()) { ScenarioUtils.log("Directory already exists: " + dir); } } else { // delete only the installation dir, not the parent String[] dirs = { "lib", "bin", "config" }; for (String d : dirs) { File dirFile = new File(dir, d); if (dirFile.exists()) { FileUtils.deleteDirectory(dirFile); } } } ScenarioUtils.unzip(new File(file), dir); ScenarioUtils.setEnvironmentVariable(MAGNET_TOOL_HOME, dir.getCanonicalPath()); }
From source file:com.heliosdecompiler.helios.transformers.assemblers.KrakatauAssembler.java
@Override public byte[] assemble(String name, String contents) { if (Helios.ensurePython2Set()) { File tempFolder = null;/*from w ww. ja va2 s .com*/ File tempFile = null; String processLog = ""; try { tempFolder = Files.createTempDirectory("ka").toFile(); tempFile = new File(tempFolder, name.replace('/', File.separatorChar) + ".j"); FileUtils.write(tempFile, contents, "UTF-8", false); Process process = Helios .launchProcess(new ProcessBuilder(Settings.PYTHON2_LOCATION.get().asString(), "-O", "assemble.py", "-out", tempFolder.getAbsolutePath(), tempFile.getAbsolutePath()) .directory(Constants.KRAKATAU_DIR)); processLog = Utils.readProcess(process); return FileUtils.readFileToByteArray(new File(tempFile.toString().replace(".j", ".class"))); } catch (Exception e) { ExceptionHandler.handle(e); SWTUtil.showMessage(processLog); } finally { try { if (tempFolder != null) { FileUtils.deleteDirectory(tempFolder); } } catch (IOException e) { } if (tempFile != null) { tempFile.delete(); } } } else { SWTUtil.showMessage("You need to set Python!"); } return null; }
From source file:eu.scape_project.arc2warc.ArcMigratorTest.java
@After public void tearDown() throws Exception { FileUtils.deleteDirectory(tempDir); }