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:com.o2d.pkayjava.editor.proxy.SceneDataManager.java

private void deleteScene(String sceneName) {
    ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
    ArrayList<SceneVO> scenes = projectManager.currentProjectInfoVO.scenes;
    SceneVO sceneToDelete = null;// w ww.  ja  v  a 2s .  co m
    for (SceneVO scene : scenes) {
        if (scene.sceneName.equals(sceneName)) {
            sceneToDelete = scene;
            break;
        }
    }
    if (sceneToDelete != null) {
        scenes.remove(sceneToDelete);
    }
    projectManager.currentProjectInfoVO.scenes = scenes;
    String projPath = projectManager.getCurrentWorkingPath() + "/"
            + projectManager.currentProjectVO.projectName;
    try {
        FileUtils.writeStringToFile(new File(projPath + "/project.dt"),
                projectManager.currentProjectInfoVO.constructJsonString(), "utf-8");
        FileUtils.forceDelete(new File(projPath + "/scenes/" + sceneName + ".dt"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

@Test
public void testSaveKeyPairToFiles02() throws IOException {
    File file1 = new File("testSaveKeyPairToFiles02.private");
    File file2 = new File("testSaveKeyPairToFiles02.public");

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

    if (file2.exists())
        FileUtils.forceDelete(file2);/* w ww.  j  ava  2  s . c  o  m*/

    assertFalse("File 1 should not exist.", file1.exists());
    assertFalse("File 2 should not exist.", file2.exists());

    this.generator.saveKeyPairToFiles(TestRSAKeyPairGenerator.reusableKeyPair,
            "testSaveKeyPairToFiles02.private", "testSaveKeyPairToFiles02.public",
            "testMyPassword02".toCharArray(), "testYourPassword02".toCharArray());

    assertTrue("File 1 should exist.", file1.exists());
    assertTrue("File 2 should exist.", file2.exists());

    PrivateKey privateKey = KeyFileUtilities.readEncryptedPrivateKey(file1, "testMyPassword02".toCharArray());
    PublicKey publicKey = KeyFileUtilities.readEncryptedPublicKey(file2, "testYourPassword02".toCharArray());

    assertNotNull("The private key should not be null.", privateKey);
    assertEquals("The private key is not correct.", TestRSAKeyPairGenerator.reusableKeyPair.getPrivate(),
            privateKey);

    assertNotNull("The public key should not be null.", publicKey);
    assertEquals("The public key is not correct.", TestRSAKeyPairGenerator.reusableKeyPair.getPublic(),
            publicKey);

    FileUtils.forceDelete(file1);
    FileUtils.forceDelete(file2);
}

From source file:com.linkedin.pinot.perf.BenchmarkDictionaryCreation.java

@TearDown
public void tearDown() throws Exception {
    FileUtils.forceDelete(INDEX_DIR);
}

From source file:info.donsun.cache.filecache.FileCacheManager.java

private void deleteDir(String dir) {
    File file = new File(dir);
    if (file.exists()) {
        try {/*from  w w w  .  jav  a  2 s. co  m*/
            FileUtils.forceDelete(file);
        } catch (IOException e) {
            LOG.error(String.format("Delete %s fail", dir), e);
        }
    }
}

From source file:io.druid.data.input.impl.SqlFirehoseTest.java

@After
public void teardown() throws IOException {
    FileUtils.forceDelete(TEST_DIR);
}

From source file:com.asakusafw.testdriver.JobFlowTester.java

private void runTestInternal(Class<? extends FlowDescription> jobFlowDescriptionClass) throws IOException {
    LOG.info("?????: {}", driverContext.getCallerClass().getName());

    if (driverContext.isSkipValidateCondition() == false) {
        LOG.info("??????: {}", driverContext.getCallerClass().getName());
        validateTestCondition();//from  w  w  w  .j a  va2  s  .co m
    }

    // ?
    LOG.info("?????: {}", jobFlowDescriptionClass.getName());
    JobFlowDriver jobFlowDriver = JobFlowDriver.analyze(jobFlowDescriptionClass);
    assertFalse(jobFlowDriver.getDiagnostics().toString(), jobFlowDriver.hasError());

    // ?
    driverContext.validateCompileEnvironment();

    JobFlowClass jobFlowClass = jobFlowDriver.getJobFlowClass();
    File compileWorkDir = driverContext.getCompilerWorkingDirectory();
    if (compileWorkDir.exists()) {
        FileUtils.forceDelete(compileWorkDir);
    }

    FlowGraph flowGraph = jobFlowClass.getGraph();
    String batchId = "testing"; //$NON-NLS-1$
    String flowId = jobFlowClass.getConfig().name();
    JobflowInfo jobflowInfo = DirectFlowCompiler.compile(flowGraph, batchId, flowId, "test.jobflow", //$NON-NLS-1$
            Location.fromPath(driverContext.getClusterWorkDir(), '/'), compileWorkDir,
            Arrays.asList(new File[] { DirectFlowCompiler.toLibraryPath(jobFlowDescriptionClass) }),
            jobFlowDescriptionClass.getClassLoader(), driverContext.getOptions());

    // ?
    driverContext.validateExecutionEnvironment();

    JobflowExecutor executor = new JobflowExecutor(driverContext);
    driverContext.prepareCurrentJobflow(jobflowInfo);

    LOG.info("??????: {}", driverContext.getCallerClass().getName());
    executor.cleanWorkingDirectory();
    executor.cleanInputOutput(jobflowInfo);
    executor.cleanExtraResources(getExternalResources());

    LOG.info("??????: {}", driverContext.getCallerClass().getName());
    executor.prepareExternalResources(getExternalResources());
    executor.prepareInput(jobflowInfo, inputs);
    executor.prepareOutput(jobflowInfo, outputs);

    LOG.info("?????: {}", jobFlowDescriptionClass.getName());
    VerifyContext verifyContext = new VerifyContext(driverContext);
    executor.runJobflow(jobflowInfo);
    verifyContext.testFinished();

    LOG.info("??????: {}", driverContext.getCallerClass().getName());
    executor.verify(jobflowInfo, verifyContext, outputs);
}

From source file:com.funambol.server.config.ConfigurationTest.java

/**
 * Test of plugin handling//from  ww w  .jav a 2  s . c om
 * @throws Exception
 */
public void testPlugin_1() throws Exception {

    Configuration.getConfiguration().initializeEngineComponents();

    Boolean b = (Boolean) PrivateAccessor.getField(Configuration.getConfiguration(),
            "engineComponentsInitialized");

    assertTrue("The engine components should be initialized", b.booleanValue());

    PluginHandler pluginHandler = (PluginHandler) PrivateAccessor.getField(Configuration.getConfiguration(),
            "pluginHandler");

    Map<String, Plugin> plugins = (Map<String, Plugin>) PrivateAccessor.getField(pluginHandler, "plugins");

    assertEquals("wrong expected plugin number:", 2, plugins.size());

    //
    // Deleting plugin 3
    //
    FileUtils.forceDelete(
            new File(Configuration.getConfigPath() + "/com/funambol/server/plugin/dummy-plugin-3.xml"));
    File dirTest1 = new File(funambolHome, "com/funambol/server/config/Configuration/plugin/test-1");

    FileUtils.copyDirectory(dirTest1, runtimePluginDir, new WildcardFileFilter("*.xml"));

    // Waiting for automatic change detection
    Thread.sleep(15 * 1000);

    pluginHandler = (PluginHandler) PrivateAccessor.getField(Configuration.getConfiguration(), "pluginHandler");
    plugins = (Map<String, Plugin>) PrivateAccessor.getField(pluginHandler, "plugins");

    assertEquals("wrong expected plugin number:", 2, plugins.size());

    System.out.println("Plugins: " + plugins);
    assertNotNull(plugins.get("dummy-plugin-1.xml"));
    assertNotNull(plugins.get("dummy-plugin-5.xml"));

    Plugin plugin1 = plugins.get("dummy-plugin-1.xml");
    assertEquals("Wrong plugin name", "test-plugin-1-updated", ((DummyPlugin) plugin1).getName());
}

From source file:com.linkedin.kafka.clients.utils.tests.EmbeddedBroker.java

@Override
public void close() throws Exception {
    KafkaTestUtils.quietly(this::shutdown);
    KafkaTestUtils.quietly(this::awaitShutdown);
    KafkaTestUtils.quietly(() -> FileUtils.forceDelete(logDir));
}

From source file:cpcc.ros.sim.osm.TileCacheTest.java

@AfterMethod
public void tearDown() throws IOException {
    FileUtils.forceDelete(tempDirectory);
}

From source file:de.akquinet.innovation.play.maven.Play2InstallPlayMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    if (StringUtils.isEmpty(play2version)) {
        throw new MojoExecutionException("play2version configuration parameter is not set");
    }/*from w  w  w .  j  a va 2  s . c  o m*/
    String debugLogPrefix = "AutoInstall - Play! " + play2version + ' ';
    File play2basedirFile = new File(play2basedir);
    File play2home = new File(play2basedirFile, "play-" + play2version);
    File play2 = new File(play2home, AbstractPlay2Mojo.isWindows() ? "play.bat" : "play");

    // Is the requested Play! version already installed?
    if (play2.isFile() && play2.canExecute()) {

        getLog().info(debugLogPrefix + "is already installed in " + play2home);
        return;

    }

    getLog().info("Play! " + play2version + " download and installation, please be patient ...");
    File zipFile = new File(play2basedirFile, "play-" + play2version + ".zip");

    try {

        URL zipUrl = new URL("http://download.playframework.org/releases/play-" + play2version + ".zip");
        FileUtils.forceMkdir(play2basedirFile);

        // Download
        getLog().debug(debugLogPrefix + "is downloading to " + zipFile);
        FileUtils.copyURLToFile(zipUrl, zipFile);

        // Extract
        getLog().debug(debugLogPrefix + "is extracting to " + play2basedir);
        UnArchiver unarchiver = archiverManager.getUnArchiver(zipFile);
        unarchiver.setSourceFile(zipFile);
        unarchiver.setDestDirectory(play2basedirFile);
        unarchiver.extract();

        // Prepare
        File framework = new File(play2home, "framework");
        File build = new File(framework, AbstractPlay2Mojo.isWindows() ? "build.bat" : "build");
        if (!build.canExecute() && !build.setExecutable(true)) {
            throw new MojoExecutionException("Can't set " + build + " execution bit");
        }
        if (!play2.canExecute() && !play2.setExecutable(true)) {
            throw new MojoExecutionException("Can't set " + play2 + " execution bit");
        }

        getLog().debug(debugLogPrefix + "is now installed in " + play2home);

    } catch (NoSuchArchiverException ex) {
        throw new MojoExecutionException("Can't auto install Play! " + play2version + " in " + play2basedir,
                ex);
    } catch (IOException ex) {
        try {
            if (play2home.exists()) {
                // Clean extracted data
                FileUtils.forceDelete(play2home);
            }
        } catch (IOException ignored) {
            getLog().warn("Unable to delete extracted Play! distribution after error: " + play2home);
        }
        throw new MojoExecutionException("Can't auto install Play! " + play2version + " in " + play2basedir,
                ex);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Cannot unzip Play " + play2version + " in " + play2basedir, e);
    } finally {
        try {
            if (zipFile.exists()) {
                // Clean downloaded data
                FileUtils.forceDelete(zipFile);
            }
        } catch (IOException ignored) {
            getLog().warn("Unable to delete downloaded Play! distribution: " + zipFile);
        }
    }
}