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.exalttech.trex.stateful.utilities.FileManager.java

/**
 * Delete file from local directory//w w  w.j av  a2 s .c  o  m
 *
 * @param fileToDelete
 */
public static void deleteFile(File fileToDelete) {
    if (fileToDelete != null) {
        FileUtils.deleteQuietly(fileToDelete);
    }
}

From source file:net.rhapso.koa.tree.IOTest.java

@Before
public void setUp() throws Exception {
    data = new File("perftest");
    FileUtils.deleteQuietly(data);
    data.mkdir();//  w w w.  j  a v a  2s  . c  om
}

From source file:io.fabric8.vertx.maven.plugin.SetupMojoTest.java

@Before
public void setUp() {
    File junk = new File("target/junk");
    FileUtils.deleteQuietly(junk);
}

From source file:com.seagate.kinetic.ForkedTestTarget.java

public ForkedTestTarget(boolean clearExistingDatabase, String serverRunnerPath, int port, int tlsPort)
        throws IOException, InterruptedException, KineticException {
    super("localhost", port, tlsPort);

    FinalizedProcessBuilder finalizedProcessBuilder = new FinalizedProcessBuilder("killall", "-9", "kineticd");
    finalizedProcessBuilder.start().waitFor(10 * 1000);
    Thread.sleep(500);/* www.  j a  v a 2 s.  c  om*/

    // Since the cluster version is checked before performing an ISE we need to manually remove
    // the file used to store the cluster version
    if (clearExistingDatabase) {
        final String workingDirectory = FilenameUtils.getFullPath(serverRunnerPath);
        final String clusterStorePath = FilenameUtils.concat(workingDirectory, "cluster_version");
        FileUtils.deleteQuietly(new File(clusterStorePath));
    }

    finalizedProcessBuilder = new FinalizedProcessBuilder(serverRunnerPath);
    finalizedProcessBuilder.directory(new File("."));
    finalizedProcessBuilder.gobbleStreamsWithLogging(true);

    externalKineticServer = finalizedProcessBuilder.start();
    waitForServerReady();

    // The ForkedTestTarget only runs on x86. The x86 implementations' ISE is almost instant with small DBs so
    // it's OK to issue a kinetic ISE instead of using SSH
    if (clearExistingDatabase) {
        performISE();
    }
}

From source file:com.linkedin.pinot.filesystem.LocalPinotFS.java

@Override
public boolean move(URI srcUri, URI dstUri) throws IOException {
    File srcFile = new File(srcUri);
    File dstFile = new File(dstUri);
    if (dstFile.exists()) {
        FileUtils.deleteQuietly(dstFile);
    }//from w ww  .  j av  a2 s  .  c om
    if (!srcFile.isDirectory()) {
        dstFile.getParentFile().mkdirs();
        FileUtils.moveFile(srcFile, dstFile);
    }
    if (srcFile.isDirectory()) {
        Files.move(srcFile.toPath(), dstFile.toPath());
    }
    return true;
}

From source file:com.datatorrent.contrib.enrich.FileEnrichmentTest.java

@Test
public void testEnrichmentOperator() throws IOException, InterruptedException {
    URL origUrl = this.getClass().getResource("/productmapping.txt");

    URL fileUrl = new URL(this.getClass().getResource("/").toString() + "productmapping1.txt");
    FileUtils.deleteQuietly(new File(fileUrl.getPath()));
    FileUtils.copyFile(new File(origUrl.getPath()), new File(fileUrl.getPath()));

    MapEnricher oper = new MapEnricher();
    FSLoader store = new JsonFSLoader();
    store.setFileName(fileUrl.toString());
    oper.setLookupFields(Arrays.asList("productId"));
    oper.setIncludeFields(Arrays.asList("productCategory"));
    oper.setStore(store);/*from w  w  w. j a v  a2s. co m*/

    oper.setup(null);

    /* File contains 6 entries, but operator one entry is duplicate,
     * so cache should contains only 5 entries after scanning input file.
     */
    //Assert.assertEquals("Number of mappings ", 7, oper.cache.size());

    CollectorTestSink<Map<String, Object>> sink = new CollectorTestSink<>();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.output.setSink(tmp);

    oper.activate(null);

    oper.beginWindow(0);
    Map<String, Object> tuple = Maps.newHashMap();
    tuple.put("productId", 3);
    tuple.put("channelId", 4);
    tuple.put("amount", 10.0);

    Kryo kryo = new Kryo();
    oper.input.process(kryo.copy(tuple));

    oper.endWindow();

    oper.deactivate();

    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    Map<String, Object> emitted = sink.collectedTuples.iterator().next();

    /* The fields present in original event is kept as it is */
    Assert.assertEquals("Number of fields in emitted tuple", 4, emitted.size());
    Assert.assertEquals("value of productId is 3", tuple.get("productId"), emitted.get("productId"));
    Assert.assertEquals("value of channelId is 4", tuple.get("channelId"), emitted.get("channelId"));
    Assert.assertEquals("value of amount is 10.0", tuple.get("amount"), emitted.get("amount"));

    /* Check if productCategory is added to the event */
    Assert.assertEquals("productCategory is part of tuple", true, emitted.containsKey("productCategory"));
    Assert.assertEquals("value of product category is 1", 5, emitted.get("productCategory"));
    Assert.assertTrue(emitted.get("productCategory") instanceof Integer);
}

From source file:com.sonar.it.jenkins.orchestrator.container.Zips.java

File get(JenkinsDistribution distrib) {
    String filename = "jenkins-war-" + distrib.getVersion() + ".war";

    if (distrib.isRelease()) {
        // releases are kept in user cache
        return new File(fileSystem.sonarInstallsDir(), filename);
    }/*from  www.  j  a  va 2 s.c  o m*/
    File snapshotWar = new File(fileSystem.workspace(), filename);
    if (snapshotWar.exists() && !isUpToDate(snapshotWar)) {
        LoggerFactory.getLogger(Zips.class).info("Delete deprecated zip: " + snapshotWar);
        FileUtils.deleteQuietly(snapshotWar);
    }
    return snapshotWar;
}

From source file:com.linkedin.pinot.core.segment.store.SegmentLocalFSDirectoryTest.java

@BeforeClass
public void setUp() {
    FileUtils.deleteQuietly(TEST_DIRECTORY);
    TEST_DIRECTORY.mkdirs();//w w w  .j a  va 2 s  .co  m
    metadata = ColumnIndexDirectoryTestHelper.writeMetadata(SegmentVersion.v1);
    segmentDirectory = new SegmentLocalFSDirectory(TEST_DIRECTORY, metadata, ReadMode.mmap);
}

From source file:com.streamsets.datacollector.util.TestSystemProcess.java

@After
public void tearDown() {
    if (process != null) {
        process.cleanup();
    }
    if (tempDir != null) {
        FileUtils.deleteQuietly(tempDir);
    }
}

From source file:com.linkedin.pinot.core.segment.index.loader.LoaderUtils.java

/**
 * Write an index file to v3 format single index file and remove the old one.
 *
 * @param segmentWriter v3 format segment writer.
 * @param column column name./*from w ww  .  jav a  2  s .co  m*/
 * @param indexFile index file to write from.
 * @param indexType index type.
 * @throws IOException
 */
public static void writeIndexToV3Format(SegmentDirectory.Writer segmentWriter, String column, File indexFile,
        ColumnIndexType indexType) throws IOException {
    int fileLength = (int) indexFile.length();
    PinotDataBuffer buffer = null;
    try {
        if (segmentWriter.hasIndexFor(column, indexType)) {
            // Index already exists, try to reuse it.

            buffer = segmentWriter.getIndexFor(column, indexType);
            if (buffer.size() != fileLength) {
                // Existed index size is not equal to index file size.
                // Throw exception to drop and re-download the segment.

                String failureMessage = "V3 format segment already has " + indexType + " for column: " + column
                        + " that cannot be removed.";
                LOGGER.error(failureMessage);
                throw new IllegalStateException(failureMessage);
            }
        } else {
            // Index does not exist, create a new buffer for that.

            buffer = segmentWriter.newIndexFor(column, indexType, fileLength);
        }

        buffer.readFrom(indexFile);
    } finally {
        FileUtils.deleteQuietly(indexFile);
        if (buffer != null) {
            buffer.close();
        }
    }
}