List of usage examples for org.apache.commons.io FileUtils deleteQuietly
public static boolean deleteQuietly(File file)
From source file:com.splunk.shuttl.archiver.usecases.TwoFormatsFunctionalTest.java
@AfterMethod public void tearDown() { FileUtils.deleteQuietly(archiverData); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.file.FileListTest.java
/** * @throws Exception if the test fails//w w w . j ava2s . co m */ @Test @Alerts({ "1", "true" }) public void in() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head><title>foo</title>\n" + "<script>\n" + "function test() {\n" + " if (document.testForm.fileupload.files) {\n" + " var files = document.testForm.fileupload.files;\n" + " alert(files.length);\n" + " alert(0 in files);\n" + " }\n" + "}\n" + "</script>\n" + "</head>\n" + "<body>\n" + " <form name='testForm'>\n" + " <input type='file' id='fileupload' name='fileupload'>\n" + " </form>\n" + " <button id='testBtn' onclick='test()'>Tester</button>\n" + "</body>\n" + "</html>"; final WebDriver driver = loadPage2(html); final File tstFile = File.createTempFile("HtmlUnitUploadTest", ".txt"); try { FileUtils.writeStringToFile(tstFile, "Hello HtmlUnit", TextUtil.DEFAULT_CHARSET); final String path = tstFile.getCanonicalPath(); driver.findElement(By.name("fileupload")).sendKeys(path); driver.findElement(By.id("testBtn")).click(); verifyAlerts(driver, getExpectedAlerts()); } finally { FileUtils.deleteQuietly(tstFile); } }
From source file:com.thoughtworks.go.security.GoCipherTest.java
@Test public void shouldWorkEvenAfterCipherFileHasBeenDeleted() throws CryptoException, IOException {//serialization friendliness resetCipher.setupAESCipherFile();// w w w .j a va 2 s. com resetCipher.setupDESCipherFile(); GoCipher goCipher = new GoCipher(systemEnvironment); FileUtils.deleteQuietly(desCipherFile); FileUtils.deleteQuietly(aesCipherFile); assertThat(desCipherFile.exists()).isFalse(); assertThat(aesCipherFile.exists()).isFalse(); String plainText = goCipher.decrypt(goCipher.encrypt("user-password!")); assertThat(plainText).isEqualTo("user-password!"); assertThat(desCipherFile.exists()).isFalse(); assertThat(aesCipherFile.exists()).isFalse(); }
From source file:com.perceptive.epm.perkolcentral.action.ExcelReportAction.java
public String execute() throws ExceptionWrapper { try {/*w ww .ja v a 2 s . c o m*/ if (reportKey.equalsIgnoreCase(Constants.REPORT_ALL_USER)) { reportName = Constants.REPORT_ALL_USER + ".xlsx"; File tempFile = new File( FilenameUtils.concat(FileUtils.getTempDirectoryPath(), UUID.randomUUID() + ".xlsx")); FileUtils.copyInputStreamToFile(ServletActionContext.getServletContext().getResourceAsStream( String.format("%s/%s", pathToExcelReportTemplateFolder, "AllEmployeeReportTemplate.xlsx")), tempFile); reportInputStream = excelReportBL.generateAllEmployeeReport(tempFile); FileUtils.deleteQuietly(tempFile); } if (reportKey.equalsIgnoreCase(Constants.REPORT_ALL_USER_SCRUM_TEAM_WISE)) { reportName = Constants.REPORT_ALL_USER_SCRUM_TEAM_WISE + ".xlsx"; File tempFile = new File( FilenameUtils.concat(FileUtils.getTempDirectoryPath(), UUID.randomUUID() + ".xlsx")); FileUtils.copyInputStreamToFile( ServletActionContext.getServletContext().getResourceAsStream(String.format("%s/%s", pathToExcelReportTemplateFolder, "AllEmployeeScrumTeamWiseReportTemplate.xlsx")), tempFile); reportInputStream = excelReportBL.generateAllEmployeeTeamWiseReport(tempFile, true); FileUtils.deleteQuietly(tempFile); } if (reportKey.equalsIgnoreCase(Constants.REPORT_ALL_USER_NONSCRUM_TEAM_WISE)) { reportName = Constants.REPORT_ALL_USER_NONSCRUM_TEAM_WISE + ".xlsx"; File tempFile = new File( FilenameUtils.concat(FileUtils.getTempDirectoryPath(), UUID.randomUUID() + ".xlsx")); FileUtils.copyInputStreamToFile(ServletActionContext.getServletContext().getResourceAsStream( String.format("%s/%s", pathToExcelReportTemplateFolder, "AllEmployeeReportTemplate.xlsx")), tempFile); reportInputStream = excelReportBL.generateAllEmployeeTeamWiseReport(tempFile, false); FileUtils.deleteQuietly(tempFile); } if (reportKey.equalsIgnoreCase(Constants.REPORT_LICENSE)) { reportName = Constants.REPORT_LICENSE + ".xlsx"; File tempFile = new File( FilenameUtils.concat(FileUtils.getTempDirectoryPath(), UUID.randomUUID() + ".xlsx")); FileUtils.copyInputStreamToFile(ServletActionContext.getServletContext().getResourceAsStream( String.format("%s/%s", pathToExcelReportTemplateFolder, "LicenseReportTemplate.xlsx")), tempFile); reportInputStream = excelReportBL.generateLicenseReport(tempFile); FileUtils.deleteQuietly(tempFile); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } return SUCCESS; }
From source file:com.linkedin.pinot.index.readerwriter.VarByteSingleValueReaderWriteTest.java
/** * This test writes {@link #NUM_STRINGS} using {@link VarByteSingleValueWriter}. It then reads * the strings using {@link VarByteSingleValueReader}, and asserts that what was written is the same as * what was read in./*from w w w . j a va 2s.com*/ * * Number of docs and docs per chunk are chosen to generate complete as well partial chunks. * * @throws Exception */ @Test public void test() throws Exception { String[] expected = new String[NUM_STRINGS]; Random random = new Random(); File outFile = new File(TEST_FILE); FileUtils.deleteQuietly(outFile); int maxStringLengthInBytes = 0; for (int i = 0; i < NUM_STRINGS; i++) { expected[i] = RandomStringUtils.random(random.nextInt(MAX_STRING_LENGTH)); maxStringLengthInBytes = Math.max(maxStringLengthInBytes, expected[i].getBytes(UTF_8).length); } ChunkCompressor compressor = ChunkCompressorFactory.getCompressor("snappy"); VarByteSingleValueWriter writer = new VarByteSingleValueWriter(outFile, compressor, NUM_STRINGS, NUM_DOCS_PER_CHUNK, maxStringLengthInBytes); for (int i = 0; i < NUM_STRINGS; i++) { writer.setString(i, expected[i]); } writer.close(); PinotDataBuffer pinotDataBuffer = PinotDataBuffer.fromFile(outFile, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, getClass().getName()); ChunkDecompressor uncompressor = ChunkCompressorFactory.getDecompressor("snappy"); VarByteSingleValueReader reader = new VarByteSingleValueReader(pinotDataBuffer, uncompressor); VarByteReaderContext context = reader.createContext(); for (int i = 0; i < NUM_STRINGS; i++) { String actual = reader.getString(i, context); Assert.assertEquals(actual, expected[i]); } reader.close(); FileUtils.deleteQuietly(outFile); }
From source file:com.creactiviti.piper.core.taskhandler.script.Bash.java
@Override public String handle(Task aTask) throws Exception { File scriptFile = File.createTempFile("_script", ".sh"); File logFile = File.createTempFile("log", null); FileUtils.writeStringToFile(scriptFile, aTask.getRequiredString("script")); try (PrintStream stream = new PrintStream(logFile);) { Process chmod = Runtime.getRuntime().exec(String.format("chmod u+x %s", scriptFile.getAbsolutePath())); int chmodRetCode = chmod.waitFor(); if (chmodRetCode != 0) { throw new ExecuteException("Failed to chmod", chmodRetCode); }/*from www .j av a 2 s. co m*/ CommandLine cmd = new CommandLine(scriptFile.getAbsolutePath()); logger.debug("{}", cmd); DefaultExecutor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return FileUtils.readFileToString(logFile); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(logFile))); } finally { FileUtils.deleteQuietly(logFile); FileUtils.deleteQuietly(scriptFile); } }
From source file:com.amazonaws.codepipeline.jenkinsplugin.TestUtils.java
public static void removeSymlinkCycle() throws IOException { FileUtils.deleteQuietly(Paths.get(TEST_DIR, "Dir1", "Cycle").toFile()); }
From source file:fr.itinerennes.bundler.tasks.framework.AbstractCountedCsvTask.java
@PostExec public void prependLineCount() throws IOException { LOGGER.debug("Inserting line count at file head: {}", lineCount); final File output = getOutputFile(); final File source = File.createTempFile("itr-", output.getName(), output.getParentFile()); source.delete();// w ww . j a va 2 s. c o m FileUtils.moveFile(output, source); InputStream from = null; BufferedWriter to = null; try { from = new FileInputStream(source); to = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), CHARSET)); to.write(String.valueOf(lineCount)); to.newLine(); final LineIterator i = IOUtils.lineIterator(from, CHARSET.name()); while (i.hasNext()) { to.write(i.next()); to.newLine(); } } finally { IOUtils.closeQuietly(from); IOUtils.closeQuietly(to); FileUtils.deleteQuietly(source); } }
From source file:gov.nih.nci.caarray.plugins.agilent.AgilentTextParserTest.java
@Test public void simpleTwoLineSectionTest() throws Exception { File file = createFile(new String[] { "TYPE", "text" }, new String[] { "SECTION_1", "column1" }, new String[] { "DATA", "test string1" }, new String[] { "DATA", "test string2" }); AgilentTextParser parser = new AgilentTextParser(file); assertTrue(parser.hasNext());/*from w ww.j a v a2s. c om*/ parser.next(); assertEquals("test string1", parser.getStringValue("column1")); assertTrue(parser.hasNext()); parser.next(); assertEquals("test string2", parser.getStringValue("column1")); assertFalse(parser.hasNext()); FileUtils.deleteQuietly(file); }
From source file:gov.nih.nci.caintegrator.file.FileManagerImpl.java
/** * {@inheritDoc} */ public void deleteStudyDirectory(StudyConfiguration studyConfiguration) { FileUtils.deleteQuietly(getStudyDirectory(studyConfiguration)); }