Example usage for org.apache.commons.io FileUtils forceDelete

List of usage examples for org.apache.commons.io FileUtils forceDelete

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils forceDelete.

Prototype

public static void forceDelete(File file) throws IOException 

Source Link

Document

Deletes a file.

Usage

From source file:net.nicholaswilliams.java.licensing.encryption.TestFilePrivateKeyDataProvider.java

@Test
@Ignore("canRead()/canWrite() do not work on Win; setReadable()/setWritable() do not work on some Macs.")
public void testGetEncryptedPrivateKeyData02() throws IOException {
    final String fileName = "testGetEncryptedPrivateKeyData02.key";
    File file = new File(fileName);
    file = file.getCanonicalFile();//from   w w w. j a  va2  s . co m

    if (file.exists())
        FileUtils.forceDelete(file);

    byte[] data = new byte[] { 0x01, 0x71, 0x33 };

    FileUtils.writeByteArrayToFile(file, data);

    try {
        assertTrue("Setting the file to not-readable should have succeeded.", file.setReadable(false, false));
        assertFalse("The file should not be readable.", file.canRead());
        assertTrue("The file should still be writable.", file.canWrite());

        FilePrivateKeyDataProvider provider = new FilePrivateKeyDataProvider(file);

        try {
            provider.getEncryptedPrivateKeyData();
            fail("Expected exception KeyNotFoundException.");
        } catch (KeyNotFoundException e) {
            assertNotNull("The cause should not be null.", e.getCause());
        }
    } finally {
        FileUtils.forceDelete(file);
    }
}

From source file:com.hortonworks.streamline.streams.service.UDFCatalogResourceTest.java

@After
public void destroy() {
    //There is no FileStorage.destroy(), unfortunately.
    try {/*from w  ww  .  j  av a2s .co m*/
        FileUtils.forceDelete(new File(testStorageDirectory));
    } catch (IOException ioe) {
        LOG.warn("Failed to delete test storage directory {} probably due to simult access.  See exception:",
                testStorageDirectory, ioe);
    }
}

From source file:cec.easyshop.storefront.filters.AbstractAddOnFilterTest.java

private void clearUpStructure() throws IOException, InterruptedException {
    if (rootSandboxDir.exists()) {
        LOG.info("About to clear sandbox " + rootSandboxDir);
        FileUtils.forceDelete(rootSandboxDir);

        LOG.info("Sandbox exists - " + rootSandboxDir.exists());
    }/*from   w w  w.  j av  a 2  s.co m*/
}

From source file:com.mindquarry.desktop.workspace.conflict.AddConflict.java

public void beforeUpdate() throws ClientException, IOException {
    log.info("beforeUpdate: " + file.getAbsolutePath());
    File file = new File(status.getPath());

    switch (action) {
    case UNKNOWN:
        // client did not set a conflict resolution
        log.error("AddConflict with no action set: " + status.getPath());
        break;/*from  w w  w.j av a 2  s  . com*/

    case RENAME:
        log.info("renaming " + file.getAbsolutePath() + " to " + newName);

        if (status.getTextStatus() != StatusKind.unversioned) {
            // the file is added, but in order to rename it without breaking
            // the svn status we have to revert it to 'unversioned'
            client.revert(status.getPath(), true);
        }

        File destination = new File(file.getParentFile(), newName);
        FileHelper.renameTo(file, destination);
        // NOTE: this could fail if the file with newName already exists
        // although we do check this previously in isRenamePossible() it
        // can happen when there are multiple add conflicts and the user
        // chooses twice the same newName for different add conflicts -
        // this is very seldom and can simply be given as error messages

        client.add(destination.getPath(), true, true);

        break;

    case REPLACE:
        log.info("replacing with new file/folder from server: " + status.getPath());

        if (status.getTextStatus() != StatusKind.unversioned) {
            // the file is added, but in order to delete it without breaking
            // the svn status we have to revert it to 'unversioned'
            client.revert(status.getPath(), true);
        }

        FileUtils.forceDelete(file);

        break;
    }
}

From source file:edu.ur.hibernate.file.db.HbTreeFolderInfoDAOTest.java

/**
 * Setup for testing//from w w w  .  j a va2s.c o  m
 * 
 * this deletes exiting test directories if they exist
 */
@BeforeMethod
public void cleanDirectory() {
    try {
        File f = new File(properties.getProperty("HbFolderDAOTest.folder_path"));
        if (f.exists()) {
            FileUtils.forceDelete(f);
        }
        f = new File(properties.getProperty("HbFolderDAOTest.children_path"));
        if (f.exists()) {
            FileUtils.forceDelete(f);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:eu.openanalytics.rsb.data.FileResultStore.java

@PreAuthorize("hasPermission(#applicationName, 'APPLICATION_USER')")
public boolean deleteByApplicationNameAndJobId(final String applicationName, final String userName,
        final UUID jobId) throws IOException {
    final File resultFile = getResultFile(applicationName, userName, jobId);

    if (resultFile == null) {
        return false;
    }/* www. j  ava  2s.  c  om*/

    FileUtils.forceDelete(resultFile);
    return true;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload.java

/**
 * Hook method providing the actual resource stream.
 * /*from ww w  .  jav  a 2  s  .  c  o  m*/
 * @return the stream.
 */
protected IResourceStream getResourceStream() {

    IResourceStream resStream = new AbstractResourceStream() {
        private static final long serialVersionUID = 1L;
        InputStream inStream;

        @Override
        public InputStream getInputStream() throws ResourceStreamNotFoundException {
            try {
                inStream = new FileInputStream(fileName);
            } catch (IOException e) {
            }
            return inStream;
        }

        @Override
        public void close() throws IOException {
            inStream.close();
            inStream = null;
            FileUtils.forceDelete(new File(fileName));
        }
    };
    return resStream;

}

From source file:com.silverpeas.wiki.WikiInstanciator.java

@Override
public void delete(Connection con, String spaceId, String componentId, String userId)
        throws InstanciationException {
    SilverTrace.info("wiki", "WikiInstanciator.delete()", "root.MSG_GEN_PARAM_VALUE",
            "spaceId = " + spaceId + " , componentId = " + componentId);
    try {/*from   w  w w .j  a  v a 2 s.  co  m*/
        wikiDAO.deleteAllPages(componentId);
    } catch (Exception e) {
        SilverTrace.info("wiki", "WikiInstanciator.delete()", "root.EX_RECORD_DELETE_FAILED",
                "componentId " + componentId, e);
    }
    new SimpleDocumentInstanciator().delete(componentId);
    try {
        FileUtils.forceDelete(getComponentDirectory(componentId));
    } catch (Exception e) {
        SilverTrace.info("wiki", "WikiInstanciator.delete()", "root.EX_RECORD_DELETE_FAILED",
                "componentId " + componentId, e);
    }
}

From source file:functionaltests.workflow.TestJobCoverage.java

@Test
public void testJobCoverage() throws Throwable {
    JobState jstate;//www .jav a 2s  .co m
    TaskInfo tinfo;
    JobInfo jinfo;

    // removing temp file if existing
    File w3File = new File(System.getProperty("java.io.tmpdir"), "WorkingAt3rdT2_13031984.tmp");
    if (w3File.exists()) {
        FileUtils.forceDelete(w3File);
    }

    //job submission
    log("Submitting job...");
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory()
            .createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
    JobId id = schedulerHelper.submitJob(job);

    //checking all processes
    log("Checking all received events :");
    jstate = schedulerHelper.waitForEventJobSubmitted(id);
    assertEquals(JobStatus.PENDING, jstate.getStatus());

    //checking task 1
    log("Checking task1 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task1");
    jstate.update(tinfo);
    jstate.update(tinfo.getJobInfo());
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    assertEquals(JobStatus.RUNNING, jstate.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task1");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FINISHED, tinfo.getStatus());

    //checking task 2
    log("Checking task2 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task2");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());

    //checking task 3
    log("Checking task3 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task3");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FINISHED, tinfo.getStatus());

    //checking task 4
    log("Checking task4 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task4");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task4");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());

    //checking task 5
    log("Checking task5 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    String hostName = tinfo.getExecutionHostName();

    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    Assert.assertFalse(hostName.equals(tinfo.getExecutionHostName()));
    hostName = tinfo.getExecutionHostName();

    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());
    Assert.assertFalse(hostName.equals(tinfo.getExecutionHostName()));

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task5");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());

    //checking task 6
    log("Checking task6 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task6");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task6");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FINISHED, tinfo.getStatus());

    //checking task 7
    log("Checking task7 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task7");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task7");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());

    //checking task 8
    log("Checking task8 process...");
    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskWaitingForRestart(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.WAITING_ON_ERROR, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskRunning(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.RUNNING, tinfo.getStatus());

    tinfo = schedulerHelper.waitForEventTaskFinished(id, "task8");
    jstate.update(tinfo);
    assertEquals(TaskStatus.FAULTY, tinfo.getStatus());

    //waiting for job termination
    log("Waiting for job to finish...");
    jinfo = schedulerHelper.waitForEventJobFinished(id);

    //checking results
    log("Checking results...");
    JobResult result = schedulerHelper.getJobResult(id);
    assertEquals(8, result.getAllResults().size());
    assertEquals(2, result.getPreciousResults().size());
    assertNotNull(result.getPreciousResults().get("task1"));
    assertNotNull(result.getPreciousResults().get("task6"));

    assertEquals("Working", result.getPreciousResults().get("task1").value());
    assertTrue(StackTraceUtil.getStackTrace(result.getResult("task2").getException())
            .contains("WorkingAt3rd - Status : Number is 1"));
    assertTrue(result.getResult("task3").value().toString()
            .contains("WorkingAt3rd - Status : OK / File deleted :"));
    assertTrue(result.getResult("task4").getException().getCause().getMessage().contains("Throwing"));
    assertTrue(result.getResult("task5").getException().getCause().getMessage().contains("Throwing"));
    assertNotNull(result.getResult("task7").getException());
    assertNotNull(result.getResult("task8").getException());

    //checking end of the job...
    jstate.update(jinfo);
    assertEquals(0, jinfo.getNumberOfPendingTasks());
    assertEquals(0, jinfo.getNumberOfRunningTasks());
    assertEquals(8, jinfo.getNumberOfFinishedTasks());
    assertEquals(8, jinfo.getTotalNumberOfTasks());
    assertEquals(JobStatus.FINISHED, jinfo.getStatus());

    assertEquals(0, jstate.getNumberOfPendingTasks());
    assertEquals(0, jstate.getNumberOfRunningTasks());
    assertEquals(8, jstate.getNumberOfFinishedTasks());
    assertEquals(8, jstate.getTotalNumberOfTasks());
    assertEquals(JobStatus.FINISHED, jstate.getStatus());

}

From source file:com.gargoylesoftware.htmlunit.util.DebuggingWebConnection.java

/**
 * Wraps a web connection to have a report generated of the received responses.
 * @param webConnection the webConnection that do the real work
 * @param dirName the name of the directory to create in the tmp folder to save received responses.
 * If this folder already exists, it will be deleted first.
 * @throws IOException in case of problems writing the files
 *///from   w  ww  . j a va2  s  .  c om
public DebuggingWebConnection(final WebConnection webConnection, final String dirName) throws IOException {

    super(webConnection);

    wrappedWebConnection_ = webConnection;
    final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    reportFolder_ = new File(tmpDir, dirName);
    if (reportFolder_.exists()) {
        FileUtils.forceDelete(reportFolder_);
    }
    FileUtils.forceMkdir(reportFolder_);
    javaScriptFile_ = new File(reportFolder_, "hu.js");
    createOverview();
}