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

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

Introduction

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

Prototype

public static boolean deleteQuietly(File file) 

Source Link

Document

Deletes a file, never throwing an exception.

Usage

From source file:com.cloudera.knittingboar.conf.cmdline.TestDataConverterDriver.java

public void testBasics() throws Exception {
    File twentyNewsGroupDataDir = DataUtils.getTwentyNewsGroupDir();
    File inputDir = new File(twentyNewsGroupDataDir, "20news-bydate-train");
    File outputDir = new File(twentyNewsGroupDataDir, "20news-bydate-converted");
    FileUtils.deleteQuietly(outputDir);
    if (!(outputDir.isDirectory() || outputDir.mkdir())) {
        throw new IOException("Could not mkdir " + outputDir);
    }//from  ww  w.j  a  v a2  s  .  c o m
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    String[] params = new String[] { "--input", inputDir.getAbsolutePath() + "/", "--output",
            outputDir.getAbsolutePath() + "/", "--recordsPerBlock", "2000" };
    DataConverterCmdLineDriver.mainToOutput(params, pw);
    String trainOut = sw.toString();
    assertTrue(trainOut.contains("Total Records Converted: 11314"));
    File[] files = outputDir.listFiles();
    for (int x = 0; x < files.length; x++) {
        System.out.println(files[x].toString());
    }
    assertEquals(6, files.length);
}

From source file:ch.vorburger.mariadb4j.tests.MariaDB4jSampleOtherTest.java

/**
 * This test ensure that there is no conflict between sockets if two MariaDB4j run on the same port.
 *//*from  w w  w .j av a 2s .c o  m*/
@Test
public void startTwoMariaDB4j() throws Exception {
    DB db1 = startNewDB();
    DB db2 = startNewDB();
    db1.stop();
    db2.stop();
    // see below in customBaseDir() why we need this here
    FileUtils.deleteQuietly(new File(db1.getConfiguration().getBaseDir()));

}

From source file:$.MarkdownMojoTest.java

@Before
    public void setUp() {
        FileUtils.deleteQuietly(basedir);
    }

From source file:com.galenframework.tests.utils.GalenUtilsTest.java

@Test
public void shouldReadFile() throws Exception {
    File testFile = File.createTempFile("testFile", ".txt");
    InputStream fileStream = GalenUtils.findFileOrResourceAsStream(testFile.getAbsolutePath());
    assertThat(fileStream, notNullValue());
    FileUtils.deleteQuietly(testFile);
}

From source file:com.adguard.compiler.PackageUtils.java

public static File createXpi(String makeXpiSh, File file, String xpiName) throws Exception {
    execute(makeXpiSh, file.getAbsolutePath());
    File xpiFile = new File(file, xpiName + ".xpi");
    File destXpiFile = new File(file.getParentFile(), file.getName() + ".xpi");
    if (destXpiFile.exists()) {
        FileUtils.deleteQuietly(destXpiFile);
    }/*  w w  w  . ja  v  a 2s  . c  om*/
    FileUtils.moveFile(xpiFile, destXpiFile);
    FileUtils.deleteQuietly(file);
    return destXpiFile;
}

From source file:com.splunk.shuttl.archiver.thaw.ThawBucketLockerTest.java

@AfterMethod
public void tearDown() {
    FileUtils.deleteQuietly(thawLocksDirectory);
}

From source file:com.gs.obevo.db.scenariotests.OnboardingDeployTest.java

@Test
public void onboardingTest() throws Exception {
    final File srcDir = new File("./src/test/resources/scenariotests/onboardingDeploy");
    final File destDir = new File("./target/scenariotests/onboardingDeploy");
    FileUtils.deleteQuietly(destDir);

    FileUtils.copyDirectory(srcDir, destDir);

    LOG.info("Part 1 - do the deployment w/ onboarding mode");
    DbDeployerAppContext deployContext = DbEnvironmentFactory.getInstance()
            .readOneFromSourcePath(destDir.getAbsolutePath(), "test").buildAppContext();

    try {/*from  w w w . j  a  v  a  2s  .  co  m*/
        deployContext.setupEnvInfra().cleanEnvironment().deploy(new MainDeployerArgs().onboardingMode(true));
    } catch (RuntimeException exc) {
        exc.printStackTrace();
        // ignoring
    }

    // Verify that the exception files have been created properly
    assertTrue(new File(destDir, "SCHEMA1/staticdata/exceptions/TABLE_A.csv").exists());
    assertTrue(new File(destDir, "SCHEMA1/staticdata/exceptions/TABLE_B.csv").exists());
    assertTrue(new File(destDir, "SCHEMA1/table/exceptions/TABLE_C.ddl").exists());
    assertTrue(new File(destDir, "SCHEMA1/table/exceptions/TABLE_WITH_ERROR.ddl").exists());
    assertTrue(new File(destDir, "SCHEMA1/view/exceptions/VIEW_WITH_ERROR.sql").exists());
    assertTrue(new File(destDir, "SCHEMA1/view/dependentOnExceptions/VIEW_DEPENDING_ON_BAD_VIEW.sql").exists());

    LOG.info("Part 2 - rerun the deploy and ensure the data remains as is");
    deployContext = DbEnvironmentFactory.getInstance().readOneFromSourcePath(destDir.getAbsolutePath(), "test")
            .buildAppContext();

    try {
        deployContext.deploy(new MainDeployerArgs().onboardingMode(true));
    } catch (RuntimeException exc) {
        exc.printStackTrace();
        // ignoring
    }

    // Same assertions as before should hold
    assertTrue(new File(destDir, "SCHEMA1/staticdata/exceptions/TABLE_A.csv").exists());
    assertTrue(new File(destDir, "SCHEMA1/staticdata/exceptions/TABLE_B.csv").exists());
    assertTrue(new File(destDir, "SCHEMA1/table/exceptions/TABLE_C.ddl").exists());
    assertTrue(new File(destDir, "SCHEMA1/table/exceptions/TABLE_WITH_ERROR.ddl").exists());
    assertTrue(new File(destDir, "SCHEMA1/view/exceptions/VIEW_WITH_ERROR.sql").exists());
    assertTrue(new File(destDir, "SCHEMA1/view/dependentOnExceptions/VIEW_DEPENDING_ON_BAD_VIEW.sql").exists());

    LOG.info("Part 3 - fix the view and verify that it is moved back to the regular folder");
    FileUtils.copyFile(new File(srcDir, "VIEW_WITH_ERROR.corrected.sql"),
            new File(destDir, "SCHEMA1/view/exceptions/VIEW_WITH_ERROR.sql"));

    deployContext = DbEnvironmentFactory.getInstance().readOneFromSourcePath(destDir.getAbsolutePath(), "test")
            .buildAppContext();

    try {
        deployContext.deploy(new MainDeployerArgs().onboardingMode(true));
    } catch (RuntimeException exc) {
        exc.printStackTrace();
        // ignoring
    }

    assertTrue(new File(destDir, "SCHEMA1/staticdata/exceptions/TABLE_A.csv").exists());
    assertTrue(new File(destDir, "SCHEMA1/staticdata/exceptions/TABLE_B.csv").exists());
    assertTrue(new File(destDir, "SCHEMA1/table/exceptions/TABLE_C.ddl").exists());
    assertTrue(new File(destDir, "SCHEMA1/table/exceptions/TABLE_WITH_ERROR.ddl").exists());
    // These two have changed from above
    assertTrue(new File(destDir, "SCHEMA1/view/VIEW_WITH_ERROR.sql").exists());
    assertTrue(new File(destDir, "SCHEMA1/view/VIEW_DEPENDING_ON_BAD_VIEW.sql").exists());
}

From source file:com.adaptris.core.fs.MarshallingCacheCase.java

@Override
public void tearDown() throws Exception {
    FileUtils.deleteQuietly(persistentStore);
    super.tearDown();
}

From source file:com.izforge.izpack.compiler.container.provider.JarOutputStreamProvider.java

public JarOutputStream provide(CompilerData compilerData) {
    File file = new File(compilerData.getOutput());
    JarOutputStream jarOutputStream = null;
    FileOutputStream fileOutputStream = null;
    FileUtils.deleteQuietly(file);
    try {/*from   w  w w .  j a v a2 s . c  o m*/
        if (compilerData.isMkdirs()) {
            FileUtils.forceMkdirParent(file);
        }
        fileOutputStream = new FileOutputStream(file);
        jarOutputStream = new JarOutputStream(fileOutputStream);
        int level = compilerData.getComprLevel();
        if (level >= 0 && level < 10) {
            jarOutputStream.setLevel(level);
        } else {
            jarOutputStream.setLevel(Deflater.BEST_COMPRESSION);
        }
    } catch (IOException e) {
        IOUtils.closeQuietly(fileOutputStream);
    }

    return jarOutputStream;
}

From source file:com.door43.translationstudio.core.TargetTranslationMigrator.java

/**
 * Performs a migration on a manifest object.
 * We just throw it into a temporary directory and run the normal migration on it.
 * @param manifestJson/*from w  w  w  .j a  v  a  2  s.  c o m*/
 * @return
 */
public static JSONObject migrateManifest(JSONObject manifestJson) {
    File tempDir = new File(AppContext.context().getCacheDir(), System.currentTimeMillis() + "");
    // TRICKY: the migration can change the name of the translation dir so we nest it to avoid conflicts.
    File fakeTranslationDir = new File(tempDir, "translation");
    fakeTranslationDir.mkdirs();
    JSONObject migratedManifest = null;
    try {
        FileUtils.writeStringToFile(new File(fakeTranslationDir, "manifest.json"), manifestJson.toString());
        fakeTranslationDir = migrate(fakeTranslationDir);
        if (fakeTranslationDir != null) {
            migratedManifest = new JSONObject(
                    FileUtils.readFileToString(new File(fakeTranslationDir, "manifest.json")));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // clean up
        FileUtils.deleteQuietly(tempDir);
    }
    return migratedManifest;
}