List of usage examples for org.apache.commons.io FileUtils deleteQuietly
public static boolean deleteQuietly(File file)
From source file:com.gargoylesoftware.htmlunit.javascript.host.URLTest.java
/** * @throws Exception if the test fails//from w ww .ja v a 2s.c o m */ @Test @NotYetImplemented public void createObjectURL() 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" + " var url = window.URL.createObjectURL(files[0]);\n" + " alert(url);\n" + " window.URL.revokeObjectURL(url);\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(); final String url = getCollectedAlerts(driver).get(0); Assert.assertTrue(url, url.startsWith("blob:")); } finally { FileUtils.deleteQuietly(tstFile); } }
From source file:com.splunk.shuttl.archiver.archive.BucketFreezerSuccessfulArchivingTest.java
public void freezeBucket_givenNonExistingSafeLocation_createSafeLocation() throws IOException { File dirToBeMoved = createDirectory(); System.err.println(tempTestDirectory); assertTrue(FileUtils.deleteQuietly(tempTestDirectory)); File nonExistingSafeLocation = tempTestDirectory; assertTrue(!nonExistingSafeLocation.exists()); System.err.println(tempTestDirectory.getName()); // Test/*from w w w.j av a 2s .co m*/ bucketFreezer.freezeBucket("index", dirToBeMoved.getAbsolutePath()); // Verify assertTrue(!dirToBeMoved.exists()); assertTrue(nonExistingSafeLocation.exists()); }
From source file:com.shopzilla.hadoop.repl.commands.util.ClusterStateManager.java
public void serializePath(final Path path, final File output) throws Exception { final File tmpRoot = Files.createTempDir(); final File tmp = new File(tmpRoot, "hdfs"); FileUtils.forceMkdir(tmp);//from www .j av a 2s . c o m new FsShell(fs.getConf()).run(new String[] { "-copyToLocal", path.toString(), tmp.getAbsolutePath() }); compressFile(tmp, output); FileUtils.deleteQuietly(tmpRoot); }
From source file:com.samczsun.helios.transformers.assemblers.SmaliAssembler.java
@Override public byte[] assemble(String name, String contents) { File tempDir = null;/*from w w w . j a va 2 s . co m*/ File tempSmaliFolder = null; File tempSmali = null; File tempDex = null; File tempJar = null; File tempJarFolder = null; try { tempDir = Files.createTempDirectory("smali").toFile(); tempSmaliFolder = new File(tempDir, "smalifolder"); tempSmaliFolder.mkdir(); tempSmali = new File(tempDir, "temp.smali"); tempDex = new File(tempDir, "temp.dex"); tempJar = new File(tempDir, "temp.jar"); tempJarFolder = new File(tempDir, "temp-jar"); FileUtils.write(tempSmali, contents, "UTF-8", false); try { org.jf.smali.main .main(new String[] { tempSmaliFolder.getAbsolutePath(), "-o", tempDex.getAbsolutePath() }); } catch (Exception e) { ExceptionHandler.handle(e); } if (Settings.APK_CONVERSION.get().asString().equals(Converter.ENJARIFY.getId())) { Converter.ENJARIFY.convert(tempDex, tempJar); } else if (Settings.APK_CONVERSION.get().asString().equals(Converter.DEX2JAR.getId())) { Converter.DEX2JAR.convert(tempDex, tempJar); } ZipUtil.unpack(tempJar, tempJarFolder); File outputClass = null; boolean found = false; File current = tempJarFolder; try { while (!found) { File f = current.listFiles()[0]; if (f.isDirectory()) current = f; else { outputClass = f; found = true; } } return org.apache.commons.io.FileUtils.readFileToByteArray(outputClass); } catch (java.lang.NullPointerException e) { } } catch (Exception e) { ExceptionHandler.handle(e); } finally { FileUtils.deleteQuietly(tempDir); FileUtils.deleteQuietly(tempSmaliFolder); FileUtils.deleteQuietly(tempSmali); FileUtils.deleteQuietly(tempDex); FileUtils.deleteQuietly(tempJar); FileUtils.deleteQuietly(tempJarFolder); } return null; }
From source file:com.heliosdecompiler.helios.transformers.disassemblers.KrakatauDisassembler.java
public boolean disassembleClassNode(ClassNode cn, byte[] b, StringBuilder output) { if (Helios.ensurePython2Set()) { File inputJar = null;// ww w .j a v a2s . com File outputZip = null; String processLog = null; try { inputJar = Files.createTempFile("kdisin", ".jar").toFile(); outputZip = Files.createTempFile("kdisout", ".zip").toFile(); Map<String, byte[]> data = Helios.getAllLoadedData(); data.put(cn.name + ".class", b); Utils.saveClasses(inputJar, data); Process process = Helios.launchProcess(new ProcessBuilder( com.heliosdecompiler.helios.Settings.PYTHON2_LOCATION.get().asString(), "-O", "disassemble.py", "-path", inputJar.getAbsolutePath(), "-out", outputZip.getAbsolutePath(), cn.name + ".class", Settings.ROUNDTRIP.isEnabled() ? "-roundtrip" : "") .directory(Constants.KRAKATAU_DIR)); processLog = Utils.readProcess(process); ZipFile zipFile = new ZipFile(outputZip); Enumeration<? extends ZipEntry> entries = zipFile.entries(); byte[] disassembled = null; while (entries.hasMoreElements()) { ZipEntry next = entries.nextElement(); if (next.getName().equals(cn.name + ".j")) { disassembled = IOUtils.toByteArray(zipFile.getInputStream(next)); } } zipFile.close(); output.append(new String(disassembled, "UTF-8")); return true; } catch (Exception e) { output.append(parseException(e)).append(processLog); return false; } finally { FileUtils.deleteQuietly(inputJar); FileUtils.deleteQuietly(outputZip); } } else { output.append("You need to set the location of Python 2.x"); } return false; }
From source file:com.impetus.ankush.agent.action.impl.XMLManipulatorTest.java
/** * Run the boolean deleteConfValue(String,String) method test. * /*from www. j a va2 s. c o m*/ * @throws Exception */ @Test public void testDeleteConfValue_3() throws Exception { String propertyName = ""; String file = "abcde.xml"; boolean result = xmlManipulator.deleteConfValue(file, propertyName); FileUtils.deleteQuietly(new File(file)); assertEquals(false, result); }
From source file:com.linkedin.pinot.tools.admin.command.UploadSegmentCommand.java
@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); }/*from w ww. j av a 2 s . co m*/ // Create a temp working directory. File tmpDir = File.createTempFile(SEGMENT_UPLOADER, null, FileUtils.getTempDirectory()); FileUtils.deleteQuietly(tmpDir); tmpDir.mkdir(); try { LOGGER.info("Executing command: " + toString()); File dir = new File(_segmentDir); File[] files = dir.listFiles(); for (File file : files) { File tgzFile = file; if (file.isDirectory()) { LOGGER.info("Compressing segment {}", file.getName()); String srcDir = file.getAbsolutePath(); String tgzFileName = TarGzCompressionUtils.createTarGzOfDirectory(srcDir, tmpDir.getAbsolutePath() + File.separator + file.getName() + TAR_GZIP); tgzFile = new File(tgzFileName); } LOGGER.info("Uploading segment {}", tgzFile.getName()); FileUploadUtils.sendSegmentFile(_controllerHost, _controllerPort, tgzFile.getName(), new FileInputStream(tgzFile), tgzFile.length()); } } catch (Exception e) { LOGGER.error("Exception caught while uploading segment {}", _segmentDir, e); } finally { // Delete the temporary working directory. FileUtils.deleteQuietly(tmpDir); } return true; }
From source file:com.adobe.people.jedelson.rugsinlambda.helpers.RugWrapper.java
public void cleanup() { FileUtils.deleteQuietly(tmpRoot); }
From source file:com.thoughtworks.go.config.materials.svn.SvnMaterialUpdaterTest.java
@Test void shouldDoAFreshCheckoutIfDestIsNotARepo() { updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); console.clear();/*from w ww .j a va 2 s . c o m*/ FileUtils.deleteQuietly(new File(workingDir, "svnDir/.svn")); updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); assertThat(console.output()).contains("Checked out revision"); assertThat(console.output()).doesNotContain("Updating"); }