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:ch.systemsx.cisd.openbis.generic.client.web.server.UploadedFilesBean.java

private final File createTempFile() throws IOException {
    final File tempFile = File.createTempFile(CLASS_SIMPLE_NAME, null);
    tempFile.deleteOnExit();
    return tempFile;
}

From source file:com.cloudera.oryx.rdf.serving.generation.RDFGenerationManager.java

@Override
protected void loadRecentModel(int mostRecentModelGeneration) throws IOException {
    if (mostRecentModelGeneration <= modelGeneration) {
        return;//from  ww  w. j a  v a  2s . c  om
    }
    if (modelGeneration == NO_GENERATION) {
        log.info("Most recent generation {} is the first available one", mostRecentModelGeneration);
    } else {
        log.info("Most recent generation {} is newer than current {}", mostRecentModelGeneration,
                modelGeneration);
    }

    File modelPMMLFile = File.createTempFile("model-", ".pmml.gz");
    modelPMMLFile.deleteOnExit();
    IOUtils.delete(modelPMMLFile);

    Config config = ConfigUtils.getDefaultConfig();
    String instanceDir = config.getString("model.instance-dir");

    String generationPrefix = Namespaces.getInstanceGenerationPrefix(instanceDir, mostRecentModelGeneration);
    String modelPMMLKey = generationPrefix + "model.pmml.gz";
    Store.get().download(modelPMMLKey, modelPMMLFile);
    log.info("Loading model description from {}", modelPMMLKey);

    Pair<DecisionForest, Map<Integer, BiMap<String, Integer>>> forestAndCatalog = DecisionForestPMML
            .read(modelPMMLFile);
    IOUtils.delete(modelPMMLFile);
    log.info("Loaded model description");

    modelGeneration = mostRecentModelGeneration;
    currentModel = new Generation(forestAndCatalog.getFirst(), forestAndCatalog.getSecond());
}

From source file:com.googlecode.jsonschema2pojo.ContentResolverTest.java

private URI createSchemaFile() throws IOException {
    File tempFile = File.createTempFile("jsonschema2pojotest", "json");
    tempFile.deleteOnExit();

    OutputStream outputStream = null;
    try {/*from  ww w.  ja va  2s .co m*/
        outputStream = new FileOutputStream(tempFile);
        outputStream.write("{\"type\" : \"string\"}".getBytes("utf-8"));
    } finally {
        if (outputStream != null) {
            outputStream.close();
        }
    }

    return tempFile.toURI();
}

From source file:info.rsdev.xb4j.model.bindings.SimpleFileTypeTest.java

@Test
public void testUnmarshallFileElement() throws Exception {
    byte[] buffer = "<Root><File>".concat(base64EncodedZipfile).concat("</File></Root>").getBytes();
    ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
    Object instance = this.model.toJava(XmlStreamFactory.makeReader(stream));
    assertNotNull(instance);/*www  . ja v a  2s  .  c o m*/
    assertSame(ObjectF.class, instance.getClass());

    //Check the zipfile
    File file = ((ObjectF) instance).getFile();
    assertNotNull(file);
    file.deleteOnExit(); //cleanup when tests are finished

    //do binary file-to-file comparison
    assertTrue(FileUtils.contentEquals(zipFile, file));
}

From source file:net.sourceforge.jukebox.model.SettingsTest.java

/**
 * Tests the <code>load</code> and <code>save</code> methods.
 * @throws IOException IOException//w  ww. j  av a 2  s . c om
 * @throws ConfigurationException ConfigurationException
 */
@Test
public final void testLoad() throws IOException, ConfigurationException {
    Settings settings = new Settings();
    settings.setContentFolder("/var/media");
    settings.setPlayerUrl("http://localhost/play");
    settings.setModifiedDays(MODIFIED_DAYS);

    File file = File.createTempFile("dummy", "properties");
    file.deleteOnExit();
    PropertiesConfiguration configuration = new PropertiesConfiguration(file);
    settings.save(configuration);

    Settings savedSettings = new Settings();
    savedSettings.load(configuration);

    assertEquals(settings, savedSettings);
}

From source file:com.stratio.ingestion.sink.cassandra.CassandraSinkIT.java

private void _do() throws TTransportException, IOException, InterruptedException {
    final Context context = new Context();
    final InetSocketAddress contactPoint = CassandraTestHelper.getCassandraContactPoint();
    context.put("tables", "keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT");
    context.put("hosts", contactPoint.getAddress().getHostAddress());
    context.put("batchSize", "1");
    context.put("consistency", "QUORUM");

    final File cqlFile = File.createTempFile("flumeTest", "cql");
    cqlFile.deleteOnExit();

    IOUtils.write(/*from  w w  w.  ja  v a 2 s  .  co m*/
            "CREATE KEYSPACE IF NOT EXISTS keyspaceTestCassandraSinkIT WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };\n\n"
                    + "CREATE TABLE IF NOT EXISTS keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT ("
                    + "id uuid, bool_field boolean, int_field int, PRIMARY KEY (int_field)" + ");\n\n",
            new FileOutputStream(cqlFile));

    context.put("cqlFile", cqlFile.getAbsolutePath());
    sink = new CassandraSink();
    sink.configure(context);

    Context channelContext = new Context();
    channelContext.put("capacity", "10000");
    channelContext.put("transactionCapacity", "200");
    channel = new MemoryChannel();
    channel.setName("junitChannel");
    Configurables.configure(channel, channelContext);
    sink.setChannel(channel);

    sink.start();
    sink.stop();
}

From source file:net.hillsdon.reviki.wiki.plugin.PluginClassLoader.java

private void cacheClassPathEntries(final URL jarUrl, final String classPath) throws IOException {
    for (String entry : classPath.split("\\s")) {
        URL entryUrl = new URL("jar:" + jarUrl.toString() + "!/" + entry);
        File file = File.createTempFile("cached-", entry);
        file.deleteOnExit();
        InputStream in = entryUrl.openStream();
        FileOutputStream out = null;
        try {/*from w ww  .ja  v a2s .co  m*/
            out = new FileOutputStream(file);
            IOUtils.copy(in, out);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
        addURL(file.toURI().toURL());
    }
}

From source file:eu.planets_project.tb.impl.serialization.ExperimentFileCache.java

/**
 * /*from   w ww. j  a va 2 s . c  o  m*/
 * @return
 * @throws IOException
 */
public File createTempFile() throws IOException {
    // Create a temporary file, and ensure it will get cleaned up on exit:
    String exname = UUID.randomUUID().toString();
    File tmp = File.createTempFile(exname.toString(), expExt, cachedir);
    tmp.deleteOnExit();
    log.info("Created temp file: " + tmp);
    return tmp;
}

From source file:jease.cmf.service.Backup.java

/**
 * Dump contents of node (and all children) into a file.
 *///from  ww  w .java  2s  . c o  m
public File dump(Node node) {
    if (node == null) {
        return null;
    }
    try {
        Node nodeCopy = node.copy(true);
        nodeCopy.setParent(null);
        String filename = (StringUtils.isEmpty(nodeCopy.getId()) ? nodeCopy.getType() : nodeCopy.getId())
                + ".xml";
        File tmpDirectory = Files.createTempDirectory("jease-backup").toFile();
        tmpDirectory.deleteOnExit();
        File dumpFile = new File(tmpDirectory, filename);
        dumpFile.deleteOnExit();
        Writer writer = Files.newBufferedWriter(dumpFile.toPath());
        toXML(nodeCopy, writer);
        writer.close();
        File zipFile = Zipfiles.zip(dumpFile);
        zipFile.deleteOnExit();
        return zipFile;
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:gov.nih.nci.caintegrator.application.analysis.GctDatasetFileWriterTest.java

@Test
public void testWriteAsGct() throws IOException {
    GenomicDataQueryResult result = createTestResult();
    String testFilePath = System.getProperty("java.io.tmpdir") + File.separator + "gctTest.gct";
    File gctFile = GctDatasetFileWriter.writeAsGct(new GctDataset(result), testFilePath);
    gctFile.deleteOnExit();
    checkFile(gctFile, result, true);//from w ww .  j  a  va  2 s  .  c  o m
    gctFile = GctDatasetFileWriter.writeAsGct(new GctDataset(result, false), testFilePath);
    checkFile(gctFile, result, false);
}