List of usage examples for org.apache.commons.io FileUtils forceDelete
public static void forceDelete(File file) throws IOException
From source file:edu.ku.brc.specify.tasks.subpane.JasperReportsCache.java
/** * Clears the compiled files that are JVM dependent. * @param cachePath the path to the cache *///w w w .j a v a2s . co m protected static void clearJasperFilesOnly(final File cachePath) { try { for (Iterator<?> iter = FileUtils.iterateFiles(cachePath, new String[] { "jasper" }, false); iter .hasNext();) { FileUtils.forceDelete((File) iter.next()); } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JasperReportsCache.class, ex); log.error(ex); } }
From source file:com.meltmedia.cadmium.cli.CommitCommand.java
/** * Does the work for this command.//from w ww. j a v a 2 s . c om * * @throws Exception */ public void execute() throws Exception { String content = null; String siteUrl = null; if (params.size() == 2) { content = params.get(0); siteUrl = getSecureBaseUrl(params.get(1)); } else if (params.size() == 0) { System.err.println("The content directory and site must be specifed."); System.exit(1); } else { System.err.println("Too many parameters were specified."); System.exit(1); } GitService git = null; try { System.out.println("Getting status of [" + siteUrl + "]"); Status status = StatusCommand.getSiteStatus(siteUrl, token); if (repo != null) { status.setRepo(repo); } status.setRevision(null); System.out.println("Cloning repository that [" + siteUrl + "] is serving"); git = CloneCommand.cloneSiteRepo(status); String revision = status.getRevision(); String branch = status.getBranch(); if (!UpdateCommand.isValidBranchName(branch, UpdateRequest.CONTENT_BRANCH_PREFIX)) { throw new Exception("Cannot commit to a branch without the prefix of " + UpdateRequest.CONTENT_BRANCH_PREFIX + "."); } if (git.isTag(branch)) { throw new Exception("Cannot commit to a tag!"); } System.out.println("Cloning content from [" + content + "] to [" + siteUrl + ":" + branch + "]"); revision = CloneCommand.cloneContent(content, git, comment); System.out.println("Switching content on [" + siteUrl + "]"); if (!UpdateCommand.sendUpdateMessage(siteUrl, null, branch, revision, comment, token)) { System.err.println("Failed to update [" + siteUrl + "]"); System.exit(1); } } catch (Exception e) { System.err.println("Failed to commit changes to [" + siteUrl + "]: " + e.getMessage()); System.exit(1); } finally { if (git != null) { String dir = git.getBaseDirectory(); git.close(); FileUtils.forceDelete(new File(dir)); } } }
From source file:com.adaltas.flume.serialization.TestHeaderAndBodyTextEventSerializer.java
@Test public void testNoNewline() throws FileNotFoundException, IOException { Map<String, String> headers = new HashMap<String, String>(); headers.put("header1", "value1"); headers.put("header2", "value2"); OutputStream out = new FileOutputStream(testFile); Context context = new Context(); context.put("appendNewline", "false"); EventSerializer serializer = EventSerializerFactory.getInstance( "com.adaltas.flume.serialization.HeaderAndBodyTextEventSerializer$Builder", context, out); serializer.afterCreate();/*from w ww .j a v a2 s . c o m*/ serializer.write(EventBuilder.withBody("event 1\n", Charsets.UTF_8, headers)); serializer.write(EventBuilder.withBody("event 2\n", Charsets.UTF_8, headers)); serializer.write(EventBuilder.withBody("event 3\n", Charsets.UTF_8, headers)); serializer.flush(); serializer.beforeClose(); out.flush(); out.close(); BufferedReader reader = new BufferedReader(new FileReader(testFile)); Assert.assertEquals("{header2=value2, header1=value1} event 1", reader.readLine()); Assert.assertEquals("{header2=value2, header1=value1} event 2", reader.readLine()); Assert.assertEquals("{header2=value2, header1=value1} event 3", reader.readLine()); Assert.assertNull(reader.readLine()); reader.close(); FileUtils.forceDelete(testFile); }
From source file:lius.index.html.NekoHtmlIndexer.java
private org.jdom.Document parse(InputStream is) { File newTmpFile = null;/*from w ww . jav a 2 s .com*/ org.jdom.Document jdomDoc = null; FileInputStream fis = null; try { newTmpFile = omitXMLDeclaration(is); DOMParser parser = new DOMParser(); fis = new FileInputStream(newTmpFile.getAbsolutePath()); parser.parse(new InputSource(fis)); org.w3c.dom.Document domDoc = parser.getDocument(); jdomDoc = convert(domDoc); } catch (SAXException e) { logger.error(e.getMessage()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (JDOMException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { try { try { if (fis != null) { fis.close(); } } finally { if (newTmpFile != null) { FileUtils.forceDelete(newTmpFile); } } } catch (IOException ioe) { logger.error(ioe); } } return jdomDoc; }
From source file:my.FileBasedTestCase.java
protected File newFile(String filename) throws IOException { File destination = new File(getTestDirectory(), filename); /*// w w w .j a va 2 s . co m assertTrue( filename + "Test output data file shouldn't previously exist", !destination.exists() ); */ if (destination.exists()) { FileUtils.forceDelete(destination); } return destination; }
From source file:com.github.brandtg.discovery.TestHelixServiceDiscoveryBundle.java
@AfterClass public void afterClass() throws Exception { zkServer.shutdown(); FileUtils.forceDelete(zkRoot); }
From source file:com.asakusafw.testdriver.BatchTester.java
private void runTestInternal(Class<? extends BatchDescription> batchDescriptionClass) throws IOException { LOG.info("?????: {}", driverContext.getCallerClass().getName()); if (driverContext.isSkipValidateCondition() == false) { LOG.info("??????: {}", driverContext.getCallerClass().getName()); validateTestCondition();/*from w w w . java2 s . c o m*/ } // ? LOG.info("???????: {}", batchDescriptionClass.getName()); // ??? BatchDriver batchDriver = BatchDriver.analyze(batchDescriptionClass); assertFalse(batchDriver.getDiagnostics().toString(), batchDriver.hasError()); // ? driverContext.validateCompileEnvironment(); File compileWorkDir = driverContext.getCompilerWorkingDirectory(); if (compileWorkDir.exists()) { FileUtils.forceDelete(compileWorkDir); } File compilerOutputDir = new File(compileWorkDir, "output"); //$NON-NLS-1$ File compilerLocalWorkingDir = new File(compileWorkDir, "build"); //$NON-NLS-1$ BatchInfo batchInfo = DirectBatchCompiler.compile(batchDescriptionClass, "test.batch", //$NON-NLS-1$ Location.fromPath(driverContext.getClusterWorkDir(), '/'), compilerOutputDir, compilerLocalWorkingDir, Arrays.asList(new File[] { DirectFlowCompiler.toLibraryPath(batchDescriptionClass) }), batchDescriptionClass.getClassLoader(), driverContext.getOptions()); // ??? for (String flowId : jobFlowMap.keySet()) { if (batchInfo.findJobflow(flowId) == null) { throw new IllegalStateException( MessageFormat.format("{1}???{0}??????", driverContext.getCallerClass().getName(), flowId)); } } // ? driverContext.validateExecutionEnvironment(); LOG.info("??????: {}", driverContext.getCallerClass().getName()); JobflowExecutor executor = new JobflowExecutor(driverContext); executor.cleanWorkingDirectory(); for (JobflowInfo jobflowInfo : batchInfo.getJobflows()) { driverContext.prepareCurrentJobflow(jobflowInfo); executor.cleanInputOutput(jobflowInfo); } executor.cleanExtraResources(getExternalResources()); if (getExternalResources().isEmpty() == false) { LOG.debug("initializing external resources: {}", //$NON-NLS-1$ batchDescriptionClass.getName()); executor.prepareExternalResources(getExternalResources()); } for (JobflowInfo jobflowInfo : batchInfo.getJobflows()) { driverContext.prepareCurrentJobflow(jobflowInfo); String flowId = jobflowInfo.getJobflow().getFlowId(); JobFlowTester tester = jobFlowMap.get(flowId); if (tester != null) { LOG.debug("initializing jobflow input/output: {}#{}", //$NON-NLS-1$ batchDescriptionClass.getName(), flowId); executor.prepareInput(jobflowInfo, tester.inputs); executor.prepareOutput(jobflowInfo, tester.outputs); LOG.info("?????: {}#{}", batchDescriptionClass.getName(), flowId); VerifyContext verifyContext = new VerifyContext(driverContext); executor.runJobflow(jobflowInfo); verifyContext.testFinished(); LOG.info("???????: {}#{}", batchDescriptionClass.getName(), flowId); executor.verify(jobflowInfo, verifyContext, tester.outputs); } } }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageArchiveTest.java
/** * @throws java.lang.Exception/*from www . ja va 2 s. c o m*/ */ @After public void tearDown() throws Exception { dpA = null; File file = new File(tmpDir + "/" + testArchive); // Clean up test archive if (file.exists()) { FileUtils.forceDelete(file); } }
From source file:hoot.services.utils.MultipartSerializerTest.java
@Ignore @Test//from ww w . ja va2s . c o m @Category(UnitTest.class) public void TestserializeFGDB() throws Exception { String jobId = "123-456-789"; String wkdirpath = HOME_FOLDER + "/upload/" + jobId; File workingDir = new File(wkdirpath); FileUtils.forceMkdir(workingDir); Assert.assertTrue(workingDir.exists()); String textFieldValue = "0123456789"; File out = new File(wkdirpath + "/fgdbTest.gdb"); FileUtils.write(out, textFieldValue); // MediaType of the body part will be derived from the file. FileDataBodyPart filePart = new FileDataBodyPart("", out, MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataContentDisposition formDataContentDisposition = new FormDataContentDisposition( "form-data; name=\"eltuploadfile0\"; filename=\"fgdbTest.gdb\""); filePart.setContentDisposition(formDataContentDisposition); FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(filePart); Map<String, String> uploadedFiles = new HashMap<>(); Map<String, String> uploadedFilesPaths = new HashMap<>(); MultipartSerializer.serializeUpload(jobId, "DIR", uploadedFiles, uploadedFilesPaths, multiPart); Assert.assertEquals("GDB", uploadedFiles.get("fgdbTest")); Assert.assertEquals("fgdbTest.gdb", uploadedFilesPaths.get("fgdbTest")); File fgdbpath = new File(wkdirpath + "/fgdbTest.gdb"); Assert.assertTrue(fgdbpath.exists()); File content = new File(wkdirpath + "/fgdbTest.gdb/dummy1.gdbtable"); Assert.assertTrue(content.exists()); FileUtils.forceDelete(workingDir); }
From source file:hu.bme.mit.sette.tools.jpet.JPetRunner.java
@Override protected void afterPrepare() throws IOException { // TODO make simpler and better // ant build// w ww .ja va 2s .c o m ProcessRunner pr = new ProcessRunner(); pr.setPollIntervalInMs(1000); pr.setCommand(new String[] { "/bin/bash", "-c", "ant" }); pr.setWorkingDirectory(getRunnerProjectSettings().getBaseDirectory()); pr.addListener(new ProcessRunnerListener() { @Override public void onTick(ProcessRunner processRunner, long elapsedTimeInMs) { System.out.println("ant build tick: " + elapsedTimeInMs); } @Override public void onIOException(ProcessRunner processRunner, IOException e) { // TODO error handling e.printStackTrace(); } @Override public void onComplete(ProcessRunner processRunner) { if (processRunner.getStdout().length() > 0) { System.out.println("Ant build output:"); System.out.println("========================================"); System.out.println(processRunner.getStdout().toString()); System.out.println("========================================"); } if (processRunner.getStderr().length() > 0) { System.out.println("Ant build error output:"); System.out.println("========================================"); System.out.println(processRunner.getStderr().toString()); System.out.println("========================================"); System.out.println("Terminating"); } } @Override public void onStdoutRead(ProcessRunner processRunner, int charactersRead) { // not needed } @Override public void onStderrRead(ProcessRunner processRunner, int charactersRead) { // not needed } }); pr.execute(); if (pr.getStderr().length() > 0) { // TODO error handling // throw new SetteGeneralException("jPET ant build has failed"); throw new RuntimeException("jPET ant build has failed"); } // delete test cases directory File testCasesDirectory = getTool().getTestCasesDirectory(getRunnerProjectSettings()); if (testCasesDirectory.exists()) { FileUtils.forceDelete( new File(getRunnerProjectSettings().getBaseDirectory(), JPetTool.TESTCASES_DIRNAME)); } }