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:io.druid.data.input.impl.SqlFirehoseTest.java

@Before
public void setup() throws IOException {
    TEST_DIR = File.createTempFile(SqlFirehose.class.getSimpleName(), "testDir");
    FileUtils.forceDelete(TEST_DIR);
    FileUtils.forceMkdir(TEST_DIR);//from   w  ww  .ja  va2 s .  c o m

    final List<Map<String, Object>> inputTexts = ImmutableList.of(
            ImmutableMap.of("x", "foostring1", "timestamp", 2000),
            ImmutableMap.of("x", "foostring2", "timestamp", 2000));
    List<FileInputStream> testFile = new ArrayList<>();
    this.objectMapper = new ObjectMapper(new SmileFactory());
    int i = 0;
    for (Map m : inputTexts) {
        File file = new File(TEST_DIR, "test_" + i++);
        try (FileOutputStream fos = new FileOutputStream(file)) {
            final JsonGenerator jg = objectMapper.getFactory().createGenerator(fos);
            jg.writeStartArray();
            jg.writeObject(m);
            jg.writeEndArray();
            jg.close();
            testFile.add(new FileInputStream(file));
        }
    }

    this.fileList = testFile;
    parser = new MapInputRowParser(new TimeAndDimsParseSpec(new TimestampSpec("timestamp", "auto", null),
            new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("x")), null, null)));

    this.inputs = inputTexts;
}

From source file:hoot.services.controllers.info.ErrorLogResource.java

@PreDestroy
public void preDestrory() {
    try {//from ww  w.j av a2 s . com
        if (_exportLogPath != null && _exportLogPath.length() > 0) {
            FileUtils.forceDelete(new File(_exportLogPath));
        }
    } catch (Exception ex) {
        //TODO: throw exception here?
        log.error(ex.getMessage());
    }
}

From source file:com.opengamma.transport.TaxonomyGatheringFudgeMessageSenderTest.java

@Test(timeOut = 10000)
public void taxonomyGathering() throws IOException, InterruptedException {
    File tmpFile = File.createTempFile("TaxonomyGatheringFudgeMessageSenderTest_taxonomyGathering",
            ".properties");
    FileUtils.forceDelete(tmpFile);
    FileUtils.forceDeleteOnExit(tmpFile);

    FudgeContext context = new FudgeContext();
    CollectingFudgeMessageReceiver collectingReceiver = new CollectingFudgeMessageReceiver();
    ByteArrayFudgeMessageReceiver fudgeReceiver = new ByteArrayFudgeMessageReceiver(collectingReceiver);
    DirectInvocationByteArrayMessageSender byteArraySender = new DirectInvocationByteArrayMessageSender(
            fudgeReceiver);//from   w w  w.j a v  a  2  s. c  o m
    ByteArrayFudgeMessageSender fudgeSender = new ByteArrayFudgeMessageSender(byteArraySender, context);
    TaxonomyGatheringFudgeMessageSender gatheringSender = new TaxonomyGatheringFudgeMessageSender(fudgeSender,
            tmpFile.getAbsolutePath(), context, 1000L);

    MutableFudgeMsg msg1 = context.newMessage();
    msg1.add("name1", 1);
    msg1.add("name2", 1);
    msg1.add("name3", 1);
    msg1.add("name1", 1);
    MutableFudgeMsg msg2 = context.newMessage();
    msg1.add("name4", msg2);
    msg2.add(14, 1);
    msg2.add("name5", "foo");

    gatheringSender.send(msg1);

    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name1"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name2"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name3"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name4"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name5"));
    assertEquals(5, gatheringSender.getCurrentTaxonomy().size());

    Properties props = new Properties();
    gatheringSender.waitForNextWrite();
    InputStream is = new FileInputStream(tmpFile);
    props.load(new BufferedInputStream(is));
    is.close();

    for (Map.Entry<Object, Object> propEntry : props.entrySet()) {
        Integer ordinal = gatheringSender.getCurrentTaxonomy().get(propEntry.getValue());
        assertEquals(ordinal.intValue(), Integer.parseInt((String) propEntry.getKey()));
    }
    assertEquals(5, props.size());
}

From source file:hoot.services.controllers.info.ReportsResourceTest.java

@Test
@Category(UnitTest.class)
public void testGetMetaData() throws Exception {
    String storePath = _rps._homeFolder + "/" + _rps._rptStorePath;
    File f = new File(storePath);
    File fWks = new File(storePath + "/123_test");
    if (fWks.exists()) {
        FileUtils.forceDelete(fWks);
    }/*from w w w .  j  ava 2 s  .  co m*/
    FileUtils.forceMkdir(f);
    JSONObject res = _rps._getMetaData("123_test");
    assertNull(res.get("name"));

    FileUtils.forceMkdir(fWks);
    String currTime = "" + System.currentTimeMillis();
    JSONObject metaData = new JSONObject();
    metaData.put("name", "Test Report1");
    metaData.put("description", "This is test report 1");
    metaData.put("created", currTime);
    metaData.put("reportpath", storePath + "/123_test/report.pdf");
    File meta = new File(storePath + "/123_test/meta.data");
    FileUtils.write(meta, metaData.toJSONString());

    res = _rps._getMetaData("123_test");

    org.junit.Assert.assertEquals("Test Report1", res.get("name").toString());
    org.junit.Assert.assertEquals("This is test report 1", res.get("description").toString());
    org.junit.Assert.assertEquals(currTime, res.get("created").toString());
    org.junit.Assert.assertEquals("reportpath", storePath + "/123_test/report.pdf",
            res.get("reportpath").toString());

    FileUtils.forceDelete(fWks);

}

From source file:com.destroystokyo.paperclipmavenplugin.GenerateDataMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final File patch = new File(generatedResourceLocation, "paperMC.patch");
    final File json = new File(generatedResourceLocation, "patch.json");

    // Create the directory if needed
    if (!generatedResourceLocation.exists()) {
        try {// w w w  .  ja v  a  2  s .  c o m
            FileUtils.forceMkdir(generatedResourceLocation);
            try {
                FileUtils.forceDelete(patch);
            } catch (FileNotFoundException ignored) {
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Could not create source directory", e);
        }
    }

    if (!vanillaMinecraft.exists()) {
        throw new MojoExecutionException("vanillaMinecraft jar does not exist!");
    }

    if (!paperMinecraft.exists()) {
        throw new MojoExecutionException("paperMinecraft jar does not exist!");
    }

    // Read the files into memory
    getLog().info("Reading jars into memory");
    final byte[] vanillaMinecraftBytes;
    final byte[] paperMinecraftBytes;
    try {
        vanillaMinecraftBytes = Files.readAllBytes(vanillaMinecraft.toPath());
        paperMinecraftBytes = Files.readAllBytes(paperMinecraft.toPath());
    } catch (IOException e) {
        throw new MojoExecutionException("Error reading jars", e);
    }

    getLog().info("Creating patch");
    try (final FileOutputStream paperMinecraftPatch = new FileOutputStream(patch)) {
        Diff.diff(vanillaMinecraftBytes, paperMinecraftBytes, paperMinecraftPatch);
    } catch (InvalidHeaderException | IOException | CompressorException e) {
        throw new MojoExecutionException("Error creating patches", e);
    }

    // Add the SHA-256 hashes for the files
    final MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new MojoExecutionException("Could not create SHA-256 hasher.", e);
    }

    getLog().info("Hashing files");
    final byte[] vanillaMinecraftHash = digest.digest(vanillaMinecraftBytes);
    final byte[] paperMinecraftHash = digest.digest(paperMinecraftBytes);

    final PatchData data = new PatchData();
    data.setOriginalHash(toHex(vanillaMinecraftHash));
    data.setPatchedHash(toHex(paperMinecraftHash));
    data.setPatch("paperMC.patch");
    data.setSourceUrl("https://s3.amazonaws.com/Minecraft.Download/versions/" + mcVersion + "/minecraft_server."
            + mcVersion + ".jar");

    data.setVersion(mcVersion);

    getLog().info("Writing json file");
    Gson gson = new Gson();
    String jsonString = gson.toJson(data);

    try (final FileOutputStream fs = new FileOutputStream(json);
            final OutputStreamWriter writer = new OutputStreamWriter(fs)) {
        writer.write(jsonString);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.datatorrent.stram.cli.ApexCliTest.java

@AfterClass
public static void finished() {
    try {//from   ww w.  j  a v  a 2  s .co  m

        StramTestSupport.removeAppPackageFile();
        FileUtils.forceDelete(configFile);
        testFolder.delete();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.linkedin.pinot.core.startree.TestStarTreeSegmentCreator.java

@BeforeClass
public void beforeClass() throws Exception {
    testName = TestStarTreeSegmentCreator.class.getSimpleName();
    indexDir = new File(System.getProperty("java.io.tmpdir"), testName);
    if (indexDir.exists()) {
        FileUtils.forceDelete(indexDir);
    }//from   ww  w .j a v  a  2s.c  o m
    System.out.println("indexDir=" + indexDir);

    avroFile = new File(System.getProperty("java.io.tmpdir"), testName + ".avro");
    if (avroFile.exists()) {
        FileUtils.forceDelete(avroFile);
    }
    avroFile.deleteOnExit();
    //    createSampleAvroData(avroFile, 25000000, 128);
    //    createSampleAvroData(avroFile, 10 * 1024 * 1024, 128);
    createSampleAvroData(avroFile, 1024, 128);
}

From source file:de.jcup.code2doc.renderer.docbook.PDFSpecificationRenderer.java

@Override
public File render() throws IOException {
    if (outputFile.exists()) {
        FileUtils.forceDelete(outputFile);

    }/*from  ww  w .j av a 2  s  . co m*/
    /* +++++++++++++++++++++++++++++++++++++++++++++++++ */
    /* Create XML */
    /* +++++++++++++++++++++++++++++++++++++++++++++++++ */
    String property = System.getProperty("code2doc.renderer.docbook.keep_temporary_files");
    boolean deleteTempFilesOnExit = property == null;

    XMLSpecificationFileGenerator xmlFileGEno = new XMLSpecificationFileGenerator();
    xmlFileGEno.setFilter(getFilter());
    xmlFileGEno.setOutputFileParentFolder(outputFile.getParentFile());
    xmlFileGEno.setOutputFileName(outputFile.getName());
    xmlFileGEno.setOutputFileDeleteOnExit(deleteTempFilesOnExit);

    File xmlFile = xmlFileGEno.generate(spec);

    /* +++++++++++++++++++++++++++++++++++++++++++++++++ */
    /* Prepare PDF rendering */
    /* +++++++++++++++++++++++++++++++++++++++++++++++++ */
    PDFRenderer pdfRenderer = PDFRenderer.create("file:" + xmlFile.getAbsolutePath());
    pdfRenderer.parameter("toc.section.depth", "8");
    pdfRenderer.parameter("chapter.autolabel", "1");
    pdfRenderer.parameter("section.autolabel", "1");
    /*
     * http://docbook.sourceforge.net/release/xsl/current/doc/fo/page.width.
     * portrait.html
     */
    pdfRenderer.parameter("paper.type", "A4");

    /*
     * http://www.sagehill.net/docbookxsl/SectionNumbering.html#
     * HTMLDepthSectionNumbers
     */
    pdfRenderer.parameter("section.autolabel.max.depth", "8");

    /* http://www.sagehill.net/docbookxsl/XrefPageNums.html */
    pdfRenderer.parameter("insert.xref.page.number", "yes");

    /* ------------------------- */
    /* Source code highlighting */
    /* ------------------------- */
    // http://www.sagehill.net/docbookxsl/SyntaxHighlighting.html
    pdfRenderer.parameter("highlight.source", "1");
    // http://sourceforge.net/p/xslthl/wiki/Usage/#xalan-27
    // http://sourceforge.net/p/xslthl/wiki/Xslthl%20Configuration/
    // works: System.setProperty(Config.CONFIG_PROPERTY,
    // "file:///C:/Temp/docbook/highlighting/xslthl-config.xml");

    /* create FOP table of contents inside PDF too */
    pdfRenderer.parameter("fop1.extensions", "1"); /*
                                                   * 'fop.extensions' did
                                                   * NOT work!
                                                   */
    pdfRenderer.parameter("ulink.show", "0");

    URL config = getClass().getResource("/xsl/docbook/highlighting/xslthl-config.xml");
    if (config == null) {
        throw new IllegalStateException("hightlight config not found! Must be inside docbook4j!");
    }
    System.setProperty(Config.CONFIG_PROPERTY, config.toExternalForm());

    /*
     * customize:
     * http://sagehill.net/docbookxsl/CustomMethods.html#WriteCustomization
     */
    /*
     * parameter reference:
     * http://docbook.sourceforge.net/release/xsl/current /doc/fo/index.html
     */
    pdfRenderer.xsl("res:pdf_template.xsl");
    try {
        /* +++++++++++++++++++++++++++++++++++++++++++++++++ */
        /* Start PDF rendering*/
        /* +++++++++++++++++++++++++++++++++++++++++++++++++ */
        InputStream in = pdfRenderer.render();
        FileOutputStream out = new FileOutputStream(outputFile);
        IOUtils.copy(in, out);
        return outputFile;
    } catch (Docbook4JException e) {
        throw new IOException("Cannot create file : " + outputFile.getAbsolutePath(), e);
    }
}

From source file:com.temenos.interaction.loader.detector.DirectoryChangeActionNotifierTest.java

@Test
public void test() throws IOException, InterruptedException {
    Assert.assertNotNull(action);/*from w ww.j av  a  2  s .c  o  m*/
    Assert.assertNotNull(notifier);
    Assert.assertTrue(!notifier.getListeners().isEmpty());

    File tempDir = createTempDirectory();
    notifier.setResources(Collections.singletonList(tempDir));

    Thread.currentThread().sleep(3000);

    File tempFile = new File(tempDir, "test.file");
    tempFile.createNewFile();
    Thread.currentThread().sleep(3000);
    Assert.assertTrue(action.getCallCount() > 0);
    System.out.println(action.getLastEvent().getResource());
    FileUtils.forceDelete(tempDir);
}

From source file:com.github.blindpirate.gogradle.util.IOUtils.java

public static void forceDelete(final File file) {
    try {/*from  www .j  av  a 2 s. c o m*/
        if (file != null) {
            FileUtils.forceDelete(file);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}