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

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

Introduction

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

Prototype

public static void forceDeleteOnExit(File file) throws IOException 

Source Link

Document

Schedules a file to be deleted when JVM exits.

Usage

From source file:it.geosolutions.geobatch.actions.geonetwork.GeonetworkActionDeleteTest.java

protected void insertSome() throws IOException, GNException {
    final String TITLETOKEN = "TOKEN_FOR_TITLE";

    GNClient client = createClientAndLogin();

    File origFile = loadFile("metadata_token.xml");
    String orig = FileUtils.readFileToString(origFile);

    File tempFile = File.createTempFile("gbtest", ".xml");
    FileUtils.forceDeleteOnExit(tempFile);

    for (int i = 0; i < 5; i++) {
        String title = "GeoBatch GeoNetworkAction test" + i + " ACK00";
        String test = orig.replace(TITLETOKEN, title);
        FileUtils.writeStringToFile(tempFile, test);
        long id = insertMetadata(client, tempFile);
        LOGGER.info("Created test metadata id:" + id + " [" + title + "]");
    }/*from   ww  w .j a v  a2 s.  co  m*/

    for (int i = 0; i < 7; i++) {
        String title = "GeoBatch GeoNetworkAction test" + i + " ACK99";
        String test = orig.replace(TITLETOKEN, title);
        FileUtils.writeStringToFile(tempFile, test);
        long id = insertMetadata(client, tempFile);
        LOGGER.info("Created test metadata id:" + id + " [" + title + "]");
    }
}

From source file:com.ewcms.content.resource.service.operator.FileOperator.java

@Override
public void delete(String uri) throws IOException {
    FileUtils.forceDeleteOnExit(getLocalFile(uri));
}

From source file:gobblin.util.SchedulerUtilsTest.java

@BeforeClass
public void setUp() throws IOException {
    this.jobConfigDir = java.nio.file.Files
            .createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName()))
            .toFile();/*from  w  w  w.jav  a  2 s  .c o  m*/
    FileUtils.forceDeleteOnExit(this.jobConfigDir);
    this.subDir1 = new File(this.jobConfigDir, "test1");
    this.subDir11 = new File(this.subDir1, "test11");
    this.subDir2 = new File(this.jobConfigDir, "test2");

    this.subDir1.mkdirs();
    this.subDir11.mkdirs();
    this.subDir2.mkdirs();

    Properties rootProps = new Properties();
    rootProps.setProperty("k1", "a1");
    rootProps.setProperty("k2", "a2");
    // test-job-conf-dir/root.properties
    rootProps.store(new FileWriter(new File(this.jobConfigDir, "root.properties")), "");

    Properties props1 = new Properties();
    props1.setProperty("k1", "b1");
    props1.setProperty("k3", "a3");
    // test-job-conf-dir/test1/test.properties
    props1.store(new FileWriter(new File(this.subDir1, "test.properties")), "");

    Properties jobProps1 = new Properties();
    jobProps1.setProperty("k1", "c1");
    jobProps1.setProperty("k3", "b3");
    jobProps1.setProperty("k6", "a6");
    // test-job-conf-dir/test1/test11.pull
    jobProps1.store(new FileWriter(new File(this.subDir1, "test11.pull")), "");

    Properties jobProps2 = new Properties();
    jobProps2.setProperty("k7", "a7");
    // test-job-conf-dir/test1/test12.PULL
    jobProps2.store(new FileWriter(new File(this.subDir1, "test12.PULL")), "");

    Properties jobProps3 = new Properties();
    jobProps3.setProperty("k1", "d1");
    jobProps3.setProperty("k8", "a8");
    jobProps3.setProperty("k9", "${k8}");
    // test-job-conf-dir/test1/test11/test111.pull
    jobProps3.store(new FileWriter(new File(this.subDir11, "test111.pull")), "");

    Properties props2 = new Properties();
    props2.setProperty("k2", "b2");
    props2.setProperty("k5", "a5");
    // test-job-conf-dir/test2/test.properties
    props2.store(new FileWriter(new File(this.subDir2, "test.PROPERTIES")), "");

    Properties jobProps4 = new Properties();
    jobProps4.setProperty("k5", "b5");
    // test-job-conf-dir/test2/test21.PULL
    jobProps4.store(new FileWriter(new File(this.subDir2, "test21.PULL")), "");
}

From source file:com.joyent.manta.http.ContentTypeLookupTest.java

@Test(enabled = false)
public void canfindByMultipleMethodsNull() throws Exception {
    MantaHttpHeaders headers = new MantaHttpHeaders(EXAMPLE_HEADERS);
    ContentType troff = ContentType.create("application/x-troff");
    ContentType jsonStream = ContentType.create("application/x-json-stream");

    File temp = File.createTempFile("upload", ".unknown");
    FileUtils.forceDeleteOnExit(temp);
    Assert.assertNull(ContentTypeLookup.findOrDefaultContentType(null, "/stor/unknown", temp, null));

    temp = File.createTempFile("upload", ".unknown");
    FileUtils.forceDeleteOnExit(temp);// www  .ja va2  s  .  co m
    Assert.assertNull(ContentTypeLookup.findOrDefaultContentType(headers, "/stor/unknown", temp, null));
}

From source file:eu.freme.eservices.epublishing.EPublishingService.java

/**
  * Creates an EPUB3 file from the input stream.
  * @param metadata  Some extra meta data
  * @param in        The input. It is supposed to be a zip file. The caller of this method is responsible for closing the stream!
  * @return          The EPUB. It is the binary contents of a zipped EPUB-3 file.
  * @throws InvalidZipException//from ww  w.j a  va 2  s .  c om
  * @throws EPubCreationException
  * @throws IOException
  * @throws MissingMetadataException
 */
public byte[] createEPUB(Metadata metadata, InputStream in)
        throws InvalidZipException, EPubCreationException, IOException, MissingMetadataException {
    // initialize the class that parses the input, and passes data to the EPUB creator
    File unzippedPath = new File(tempFolderPath, "freme_epublishing_" + System.currentTimeMillis());
    FileUtils.forceDeleteOnExit(unzippedPath);

    try (ZipInputStream zin = new ZipInputStream(in, StandardCharsets.UTF_8)) {
        Unzipper.unzip(zin, unzippedPath);

        EPubCreator creator = new EPubCreatorImpl(metadata, unzippedPath);

        // write the EPUB "file", in this case to bytes
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            creator.onEnd(bos);
            return bos.toByteArray();
        }
    } catch (IOException ex) {
        Logger.getLogger(EPublishingService.class.getName()).log(Level.SEVERE, null, ex);
        throw new InvalidZipException(
                "Something went wrong with the provided Zip file. Make sure you are providing a valid Zip file.");
    } finally {
        FileUtils.deleteDirectory(unzippedPath);
    }
}

From source file:eu.freme.eservices.publishing.EPublishingService.java

/**
  * Creates an EPUB3 file from the input stream.
  * @param metadata  Some extra meta mockup-endpoint-data
  * @param in        The input. It is supposed to be a zip file. The caller of this method is responsible for closing the stream!
  * @return          The EPUB. It is the binary contents of a zipped EPUB-3 file.
  * @throws InvalidZipException// ww w.j a  v a2  s  . c om
  * @throws EPubCreationException
  * @throws IOException
  * @throws MissingMetadataException
 */
public byte[] createEPUB(Metadata metadata, InputStream in)
        throws InvalidZipException, EPubCreationException, IOException, MissingMetadataException {
    // initialize the class that parses the input, and passes mockup-endpoint-data to the EPUB creator
    File unzippedPath = new File(tempFolderPath, "freme_epublishing_" + System.currentTimeMillis());
    FileUtils.forceDeleteOnExit(unzippedPath);

    try (ZipInputStream zin = new ZipInputStream(in, StandardCharsets.UTF_8)) {
        Unzipper.unzip(zin, unzippedPath);

        EPubCreator creator = new EPubCreatorImpl(metadata, unzippedPath);

        // write the EPUB "file", in this case to bytes
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            creator.onEnd(bos);
            return bos.toByteArray();
        }
    } catch (IOException ex) {
        Logger.getLogger(EPublishingService.class.getName()).log(Level.SEVERE, null, ex);
        throw new InvalidZipException(
                "Something went wrong with the provided Zip file. Make sure you are providing a valid Zip file.");
    } finally {
        FileUtils.deleteDirectory(unzippedPath);
    }
}

From source file:gobblin.scheduler.JobConfigFileMonitorTest.java

@BeforeClass
public void setUp() throws Exception {
    this.jobConfigDir = Files
            .createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName()))
            .toString();/*from w  w w.  j  a  va  2  s.c om*/

    FileUtils.forceDeleteOnExit(new File(this.jobConfigDir));
    FileUtils.copyDirectory(new File(JOB_CONFIG_FILE_DIR), new File(jobConfigDir));

    Properties properties = new Properties();
    try (Reader schedulerPropsReader = new FileReader("gobblin-test/resource/gobblin.test.properties")) {
        properties.load(schedulerPropsReader);
    }
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, jobConfigDir);
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, jobConfigDir);
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, "1000");
    properties.setProperty(ConfigurationKeys.METRICS_ENABLED_KEY, "false");

    SchedulerService quartzService = new SchedulerService(new Properties());
    this.jobScheduler = new JobScheduler(properties, quartzService);
    this.serviceManager = new ServiceManager(Lists.newArrayList(quartzService, this.jobScheduler));
    this.serviceManager.startAsync().awaitHealthy(10, TimeUnit.SECONDS);
    ;
}

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

/**
 * Test of createPages method, of class WikiInstanciator.
 *//*www.  j  ava  2  s  . c om*/
@Test
public void testCreatePages() throws Exception {
    String instanceId = "wiki18";
    WikiPageDAO dao = mock(WikiPageDAO.class);
    WikiInstanciator instance = new WikiInstanciator(dao);
    File directory = folder.newFolder("Test de base");
    FileUtils.forceDeleteOnExit(directory);
    PageDetail aboutPage = new PageDetail();
    aboutPage.setInstanceId(instanceId);
    aboutPage.setPageName("About");
    PageDetail approvalRequiredForPageChanges = new PageDetail();
    approvalRequiredForPageChanges.setInstanceId(instanceId);
    approvalRequiredForPageChanges.setPageName("ApprovalRequiredForPageChanges");

    instance.createPages(directory, instanceId);
    assertNotNull(directory);
    verify(dao).createPage(aboutPage);
    verify(dao).createPage(approvalRequiredForPageChanges);

    Collection uncompressedFiles = FileUtils.listFiles(directory, new String[] { "txt" }, true);
    assertNotNull(uncompressedFiles.size());
    assertEquals(29, uncompressedFiles.size());

}

From source file:com.danielhalima.aem.MyMojo.java

public void execute() throws MojoExecutionException {

    getLog().info("Running archetype post processing tasks");

    File projectBasedir = new File(this.baseDirectory);

    if (projectBasedir.exists()) {
        InvocationRequest request = new DefaultInvocationRequest().setBaseDirectory(projectBasedir)
                .setGoals(Arrays.asList(new String[] { "process-sources" }));

        try {/*from  w  ww . j a v  a 2 s . com*/
            invoker.execute(request);
            if (this.deleteOnExit) {
                FileUtils.forceDeleteOnExit(projectBasedir);
            }
        } catch (MavenInvocationException e) {
            throw new MojoExecutionException("Could not run post processing tasks.", e);
        } catch (IOException e) {
            throw new MojoExecutionException("Could not delete directory " + projectBasedir + ".", e);
        }
    } else {
        getLog().info("Post processing tasks skipped: unavailable basedir " + this.baseDirectory);
    }

}

From source file:com.joyent.manta.client.crypto.SecretKeyUtilsTest.java

public void canLoadKeyFromFilePath() throws IOException {
    File file = File.createTempFile("ciphertext-", ".data");
    FileUtils.forceDeleteOnExit(file);
    FileUtils.writeByteArrayToFile(file, keyBytes);
    Path path = file.toPath();/*from  w  w  w .  j a v  a 2 s .  co  m*/

    SecretKey expected = SecretKeyUtils.loadKey(keyBytes, AesGcmCipherDetails.INSTANCE_128_BIT);
    SecretKey actual = SecretKeyUtils.loadKeyFromPath(path, AesGcmCipherDetails.INSTANCE_128_BIT);

    Assert.assertEquals(actual.getAlgorithm(), expected.getAlgorithm());
    Assert.assertTrue(Arrays.equals(expected.getEncoded(), actual.getEncoded()),
            "Secret key loaded from URI doesn't match");
}