List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:com.diffplug.gradle.FileMisc.java
/** Calls {@link FileUtils#forceDelete(File)} and throws an exception if it fails. If the file doesn't exist at all, that's fine. */ public static void forceDelete(File f) { retry(f, file -> {//from ww w . ja v a 2 s. c o m if (file.exists()) { FileUtils.forceDelete(f); } return null; }); }
From source file:com.docd.purefm.test.CommandLineFileTest.java
@Override protected void setUp() throws Exception { super.setUp(); final String state = Environment.getExternalStorageState(); if (!state.equals(Environment.MEDIA_MOUNTED)) { throw new RuntimeException( "Make sure the external storage is mounted read-write before running this test"); }/* ww w . j ava 2 s. c o m*/ try { FileUtils.forceDelete(testDir); } catch (IOException e) { //ignored } assertTrue(testDir.mkdirs()); // prepare a test file try { FileUtils.write(test1, "test"); } catch (IOException e) { throw new RuntimeException("Failed to create test file: " + e); } }
From source file:it.geosolutions.geostore.services.rest.BaseAuthenticationTest.java
@Override protected void setUp() throws Exception { super.setUp(); File securityTempFolder = new File(System.getProperty("java.io.tmpdir"), "apacheds-spring-security"); int i = 0;//from w w w. j a v a 2s . c om for (i = 0; i < 10; i++) { try { if (securityTempFolder.exists() && securityTempFolder.isDirectory() && securityTempFolder.canWrite()) { FileDeleteStrategy.FORCE.delete(securityTempFolder); FileUtils.forceDelete(securityTempFolder); } } catch (Exception e) { LOGGER.info(i * 10 + "... "); Thread.sleep(1000); continue; } break; } LOGGER.info(100); String[] paths = { "classpath*:applicationContext-test.xml" }; context = new ClassPathXmlApplicationContext(paths); LOGGER.info("Built test context: " + context); }
From source file:com.github.ipaas.ideploy.agent.handler.UpdateCodeHandlerTest.java
/** * ??,???,// w w w .j av a 2s . c o m * * @throws Exception */ @Test public void updateCodeTest() throws Exception { String usingRoot = "/www/apptemp/" + USING_VERSION; String doingRoot = "/www/apptemp/" + DOING_VERSION; DownloadCodeHandler downLoadHandler = new DownloadCodeHandler(); File usingfile = new File(usingRoot); if (usingfile.exists()) { FileUtils.forceDelete(usingfile); } File doingFile = new File(doingRoot); if (doingFile.exists()) { FileUtils.forceDelete(doingFile); } String flowId = "flowIdNotNeed"; String cmd = "cmdNotNeed"; Integer hostStatus4New = 1; Integer updateAll = 1; Map<String, Object> firstDownLoadParams = new HashMap<String, Object>(); firstDownLoadParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION); firstDownLoadParams.put("hostStatus", hostStatus4New); firstDownLoadParams.put("savePath", usingRoot);// ?? firstDownLoadParams.put("updateAll", updateAll); downLoadHandler.execute(flowId, cmd, firstDownLoadParams, null); Assert.assertTrue(new File(usingRoot + "/update.txt").exists()); Integer notUpdateAll = 2; Integer hostStatus4Old = 2; Map<String, Object> secondDownLoadParams = new HashMap<String, Object>(); secondDownLoadParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + DOING_VERSION); secondDownLoadParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION); secondDownLoadParams.put("hostStatus", hostStatus4Old); secondDownLoadParams.put("savePath", doingRoot);// ?? secondDownLoadParams.put("updateAll", notUpdateAll); downLoadHandler.execute(flowId, cmd, secondDownLoadParams, null); File updateFile = new File(doingRoot + "/update.txt"); List<String> updateList = FileUtils.readLines(updateFile); UpdateCodeHandler updateHandler = new UpdateCodeHandler(); Map<String, Object> updateParam = new HashMap<String, Object>(); updateParam.put("targetPath", usingRoot + "/code"); updateParam.put("srcPath", doingRoot); updateHandler.execute(null, null, updateParam, null);// ?doingRoot?usingRoot // ? // String do for (String str : updateList) { if (str.startsWith("+")) { Assert.assertTrue( new File(usingRoot + "/code" + StringUtils.removeStart(str, "+").trim()).exists()); } else if (str.startsWith("-")) { String f = usingRoot + "/code" + StringUtils.removeStart(str, "-").trim(); Assert.assertFalse(new File(f).exists()); } } if (usingfile.exists()) { FileUtils.forceDelete(usingfile); } }
From source file:com.netsteadfast.greenstep.util.JReportUtils.java
public static void deployReport(TbSysJreport report) throws Exception { String reportDeployDirName = Constants.getDeployJasperReportDir() + "/"; File reportDeployDir = new File(reportDeployDirName); try {//from w ww.java 2 s . c om if (!reportDeployDir.exists()) { logger.warn("no exists dir, force mkdir " + reportDeployDirName); FileUtils.forceMkdir(reportDeployDir); } } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage().toString()); } logger.info("REPORT-ID : " + report.getReportId()); File reportFile = null; File reportZipFile = null; OutputStream os = null; try { String reportFileFullPath = reportDeployDirName + report.getReportId() + "/" + report.getFile(); String reportZipFileFullPath = reportDeployDirName + report.getReportId() + ".zip"; reportZipFile = new File(reportZipFileFullPath); if (reportZipFile.exists()) { logger.warn("delete " + reportZipFileFullPath); FileUtils.forceDelete(reportZipFile); } os = new FileOutputStream(reportZipFile); IOUtils.write(report.getContent(), os); os.flush(); ZipFile zipFile = new ZipFile(reportZipFileFullPath); zipFile.extractAll(reportDeployDirName); reportFile = new File(reportFileFullPath); if (!reportFile.exists()) { logger.warn("report file is missing : " + reportFileFullPath); return; } if (YesNo.YES.equals(report.getIsCompile()) && report.getFile().endsWith("jrxml")) { logger.info("compile report..."); String outJasper = compileReportToJasperFile(new String[] { reportFileFullPath }, reportDeployDirName + report.getReportId() + "/"); logger.info("out : " + outJasper); } } catch (JRException re) { re.printStackTrace(); logger.error(re.getMessage().toString()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage().toString()); } finally { if (os != null) { os.close(); } os = null; reportFile = null; reportZipFile = null; } reportDeployDir = null; }
From source file:gov.redhawk.sca.efs.tests.ScaFileOutputStreamTest.java
/** * @throws java.lang.Exception/*from ww w . j av a 2 s. c o m*/ */ @After public void tearDown() throws Exception { this.fileSystem = null; this.rootFileStore = null; this.rootFileStoreFile = null; this.outputStream.close(); FileUtils.forceDelete(this.tempFile); }
From source file:com.alexholmes.hadooputils.test.HadoopTestCaseFixer.java
/** * Performs some additional setup required before the * {@link org.apache.hadoop.mapred.HadoopTestCase#setUp()} method can be called. * * @throws Exception if something goes wrong */// w w w . j a v a 2 s .c o m @Override @Before public void setUp() throws Exception { // this path is used by File f = new File("build/test/mapred/local").getAbsoluteFile(); if (f.exists()) { FileUtils.forceDelete(f); } FileUtils.forceMkdir(f); // required by JobHistory.initLogDir System.setProperty("hadoop.log.dir", f.getAbsolutePath()); super.setUp(); }
From source file:io.druid.data.input.impl.PrefetchableTextFilesFirehoseFactoryTest.java
@AfterClass public static void teardown() throws IOException { FileUtils.forceDelete(testDir); FileUtils.forceDelete(firehoseTempDir); }
From source file:com.alexholmes.hadooputils.test.MiniHadoop.java
/** * Creates a {@link MiniMRCluster} and {@link MiniDFSCluster} all working within * the directory supplied in {@code tmpDir}. * * The DFS will be formatted regardless if there was one or not before in the * given location./*from ww w. j a va2 s. com*/ * * @param config the Hadoop configuration * @param taskTrackers number of task trackers to start * @param dataNodes number of data nodes to start * @param tmpDir the temporary directory which the Hadoop cluster will use for storage * @throws IOException thrown if the base directory cannot be set. */ public MiniHadoop(final Configuration config, final int taskTrackers, final int dataNodes, final File tmpDir) throws IOException { if (taskTrackers < 1) { throw new IllegalArgumentException("Invalid taskTrackers value, must be greater than 0"); } if (dataNodes < 1) { throw new IllegalArgumentException("Invalid dataNodes value, must be greater than 0"); } config.set("hadoop.tmp.dir", tmpDir.getAbsolutePath()); if (tmpDir.exists()) { FileUtils.forceDelete(tmpDir); } FileUtils.forceMkdir(tmpDir); // used by MiniDFSCluster for DFS storage System.setProperty("test.build.data", new File(tmpDir, "data").getAbsolutePath()); // required by JobHistory.initLogDir System.setProperty("hadoop.log.dir", new File(tmpDir, "logs").getAbsolutePath()); JobConf jobConfig = new JobConf(config); dfsCluster = new MiniDFSCluster(jobConfig, dataNodes, true, null); fileSystem = dfsCluster.getFileSystem(); mrCluster = new MiniMRCluster(0, 0, taskTrackers, fileSystem.getUri().toString(), 1, null, null, null, jobConfig); }
From source file:com.baasbox.service.dbmanager.DbManagerService.java
public static void deleteExport(String fileName) throws FileNotFoundException, IOException { java.io.File file = new java.io.File(backupDir + fileSeparator + fileName); if (!file.exists()) { throw new FileNotFoundException("Export " + fileName + " not found"); } else {/*from ww w .j a va2 s. c om*/ boolean deleted = false; try { FileUtils.forceDelete(file); deleted = true; } catch (IOException e) { deleted = file.delete(); if (deleted == false) { file.deleteOnExit(); } } if (!deleted) { throw new IOException("Unable to delete export.It will be deleted on the next reboot." + fileName); } } }