Example usage for java.io File deleteOnExit

List of usage examples for java.io File deleteOnExit

Introduction

In this page you can find the example usage for java.io File deleteOnExit.

Prototype

public void deleteOnExit() 

Source Link

Document

Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

Usage

From source file:com.cloudera.flume.handlers.rolling.TestRollRollTags.java

@Test
public void testAgentCollector() throws FlumeSpecException, IOException, InterruptedException {
    BenchmarkHarness.setupLocalWriteDir();
    File path = File.createTempFile("collector", ".tmp");
    path.deleteOnExit();

    EventSink snk = new CompositeSink(LogicalNodeContext.testingContext(),
            "{ ackedWriteAhead => roll(1000) { dfs(\"file:///"
                    + StringEscapeUtils.escapeJava(path.getAbsolutePath()) + "\") } }");
    Event e = new EventImpl("foo".getBytes());
    snk.open();// ww w .  j  av a  2  s .  c  o  m
    snk.append(e); // should not bork.
    snk.close();
    BenchmarkHarness.cleanupLocalWriteDir();
}

From source file:com.cloudera.flume.handlers.rolling.TestRollRollTags.java

@Test
public void testAgentCollectorFixed() throws FlumeSpecException, IOException, InterruptedException {
    BenchmarkHarness.setupLocalWriteDir();
    File path = File.createTempFile("collector", ".tmp");
    path.deleteOnExit();

    EventSink snk = new CompositeSink(LogicalNodeContext.testingContext(),
            "{ ackedWriteAhead => { mask(\"rolltag\") => roll(1000) { dfs(\"file:///"
                    + StringEscapeUtils.escapeJava(path.getAbsolutePath()) + "\") } } }");
    Event e = new EventImpl("foo".getBytes());
    snk.open();//from w w  w  .j a  va  2  s .com
    snk.append(e); // should not bork.
    snk.close();
    BenchmarkHarness.cleanupLocalWriteDir();
}

From source file:com.izforge.izpack.compiler.container.TestCompilerContainer.java

/**
 * Fills the container.//from  w  ww  .ja va2 s  . co  m
 *
 * @param container the underlying container
 * @throws ContainerException if initialisation fails, or the container has already been initialised
 */
@Override
protected void fillContainer(MutablePicoContainer container) {
    super.fillContainer(container);
    try {
        deleteLock();
    } catch (IOException exception) {
        throw new ContainerException(exception);
    }
    InstallFile installFile = testMethod.getAnnotation(InstallFile.class);
    if (installFile == null) {
        installFile = testClass.getAnnotation(InstallFile.class);
    }
    String installFileName = installFile.value();

    File installerFile = FileUtil.convertUrlToFile(getClass().getClassLoader().getResource(installFileName));
    File baseDir = installerFile.getParentFile();

    File out = new File(baseDir, "out" + Math.random() + ".jar");
    out.deleteOnExit();
    CompilerData data = new CompilerData(installerFile.getAbsolutePath(), baseDir.getAbsolutePath(),
            out.getAbsolutePath(), false);
    addComponent(CompilerData.class, data);
    addComponent(File.class, out);

    container.addConfig("installFile", installerFile.getAbsolutePath());
    container.addAdapter(new JarFileProvider());
}

From source file:de.fau.cs.osr.hddiff.perfsuite.util.SerializationUtils.java

public File createTempDiffFile(PageRevDiffNode prdn) throws IOException {
    File fileDiff = File.createTempFile(makeDiffPrefix(prdn), ".xml", tempDir);
    fileDiff.deleteOnExit();
    return fileDiff;
}

From source file:cat.calidos.morfeu.utils.FileSaverTest.java

@Test
public void testSave() throws Exception {

    String tmp = setupTempDirectory();
    //System.err.println("FileSaverTest::Using '"+tmp+"' as temporary test folder");
    String path = tmp + "/filesaver-test-" + System.currentTimeMillis() + ".txt";
    File file = new File(path);
    if (file.exists() && !file.isDirectory()) {
        file.delete();//from   ww w.j  ava  2s .  c  om
    }
    file.deleteOnExit();
    String contentWritten = "foo";
    FileSaver saver = new FileSaver(path, contentWritten);
    saver.save();
    File file2 = new File(path);
    String contentRead = FileUtils.readFileToString(file2, Config.DEFAULT_CHARSET);

    assertEquals("Content written to the output file was not as expected", contentWritten, contentRead);

}

From source file:com.hortonworks.streamline.streams.catalog.configuration.ConfigFileWriterTest.java

@Test
public void writeYamlConfigToFile() throws Exception {
    Map<String, String> configuration = createDummyConfiguration();

    File destPath = Files.createTempFile("config", "yaml").toFile();
    destPath.deleteOnExit();

    writer.writeConfigToFile(ConfigFileType.YAML, configuration, destPath);
    assertTrue(destPath.exists());//from   w  ww .  j  av  a  2  s  . c  o  m
    try (InputStream is = new FileInputStream(destPath)) {
        String content = IOUtils.toString(is);
        System.out.println("Test print: yaml content - " + content);

        ObjectMapper mapper = new YAMLMapper();
        Map<String, Object> readConfig = mapper.readValue(content, Map.class);

        assertEquals(configuration, readConfig);
    }
}

From source file:edu.upf.nets.mercury.geoip.GeoIpDatabase.java

/**
 * Processes the GZIP data and loads it into the current database.
 * @param data The GeoIP data.//www.  j av a  2s.c  om
 */
private void process(byte[] data) throws GeoIpException {
    // Create an input stream from the byte array data.
    InputStream inputStream = new ByteArrayInputStream(data);

    try {
        // Create a GZIP input stream.
        GZIPInputStream zipStream = new GZIPInputStream(inputStream);
        // Create a temporary file for this database.
        File file = File.createTempFile(this.name, ".tmp");
        file.deleteOnExit();
        // Copy the data from.
        IOUtils.copy(zipStream, new FileOutputStream(file));
        // Location service.
        this.service = new LookupService(file);
    } catch (IOException exception) {
        throw new GeoIpException("Could not UNZIP the received data file.", exception);
    }
}

From source file:azkaban.web.JobManagerServlet.java

private File unzipFile(FileItem item) throws ServletException, IOException {
    File temp = File.createTempFile("job-temp", ".zip");
    temp.deleteOnExit();
    OutputStream out = new BufferedOutputStream(new FileOutputStream(temp));
    IOUtils.copy(item.getInputStream(), out);
    out.close();/* w ww  .j a  v a2 s.c om*/
    ZipFile zipfile = new ZipFile(temp);
    File unzipped = Utils.createTempDir(new File(_tempDir));
    Utils.unzip(zipfile, unzipped);
    temp.delete();
    return unzipped;
}

From source file:com.playonlinux.core.utils.archive.TarTest.java

@Test
public void testUncompress_withSymbolicLinks() throws IOException {
    final File inputFile = new File(inputUrl.getPath(), "tarLink.tar.gz");
    final File temporaryDirectory = Files.createTempDir();

    temporaryDirectory.deleteOnExit();

    final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory);

    final File file1 = new File(temporaryDirectory, "file1.txt");
    final File file2 = new File(temporaryDirectory, "file1_link.txt");

    assertTrue(file1.exists());//from w w  w  .  j  a  v a2 s . co m
    assertTrue(file2.exists());

    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1)));
    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file2)));

    assertTrue(java.nio.file.Files.isSymbolicLink(Paths.get(file2.getPath())));
}

From source file:de.fau.cs.osr.hddiff.perfsuite.util.SerializationUtils.java

public File storeWomNiceTemp(PageRevWom prw, Revision rev, Wom3Document wom) throws Exception {
    File file = File.createTempFile(makeNicePrefix(prw, rev), ".xml", tempDir);
    file.deleteOnExit();
    try (FileOutputStream fos = new FileOutputStream(file)) {
        byte[] str = serializer.serialize(wom, WomSerializer.SerializationFormat.XML, false, true);
        IOUtils.write(str, fos);//from  w  w w.  j ava2  s  .c  o m
    }
    return file;
}