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.xebialabs.deployit.cli.ext.mustachify.io.Files2.java

public static void deleteOnExit(@Nullable File file) {
    if (file != null) {
        file.deleteOnExit();
    }
}

From source file:Main.java

public static void deleteFile(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file2 : files) {
                if (file2.isDirectory()) {
                    deleteFile(file2);/*  www .j a v  a  2 s.co  m*/
                } else {
                    file2.deleteOnExit();
                }
            }
        }
        file.deleteOnExit();
    }
}

From source file:com.loy.MicroServiceConsole.java

static void killProcess() {
    for (Long pid : pids) {
        try {/*from w w w  .ja va2  s. c  o  m*/
            if (Processes.isProcessRunning(platform, pid)) {
                File pidFile = new File("./pids/" + pid.toString());
                pidFile.deleteOnExit();
                if (Platform.Windows == platform) {
                    Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                } else {
                    Processes.killProcess(null, platform, new NullProcessor(), pid);
                }
            }
        } catch (Exception ex) {
        }
    }
}

From source file:com.jaspersoft.studio.server.publish.imp.AImpObject.java

protected static File getTmpFile(String str) {
    String fname = str;//w  ww .  java2  s.  co m
    int ind = str.lastIndexOf("/");
    if (ind >= 0)
        fname = fname.substring(ind + 1);
    File f = new File(getTempDir(), fname);
    f.deleteOnExit();
    return f;
}

From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.UnixUtils.java

public static String createTempFileFromResource(final String script, final String extension,
        final boolean executable) throws IOException {
    final InputStream scriptInputStream = UnixUtils.class.getResourceAsStream("/" + script);

    // create a temporary file
    final File scriptTempFile = File.createTempFile("unix-utils-", extension);
    scriptTempFile.deleteOnExit();
    try (FileOutputStream out = new FileOutputStream(scriptTempFile)) {
        IOUtils.copy(scriptInputStream, out);
    }/* ww w . j  ava  2 s.  c o  m*/
    scriptTempFile.setExecutable(executable);

    final String command = scriptTempFile.getAbsolutePath();
    return command;
}

From source file:com.ngdata.hbaseindexer.mr.TestUtils.java

private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir)
        throws IOException {

    LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs
            + ", outputShardDir: " + outputShardDir);

    // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    FileUtils.copyDirectory(solrHomeDir, tmpDir);
    solrHomeDir = tmpDir;/*  www  .  jav  a 2s  . c om*/

    Path solrDataDir = new Path(outputShardDir, "data");

    String dataDirStr = solrDataDir.toUri().toString();

    SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

    LOG.info(String.format(Locale.ENGLISH,
            "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
            solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(), loader.getConfigDir(), dataDirStr,
            outputShardDir));

    // TODO: This is fragile and should be well documented
    System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
    System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
    System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
    System.setProperty("solr.hdfs.blockcache.enabled", "false");
    System.setProperty("solr.autoCommit.maxTime", "600000");
    System.setProperty("solr.autoSoftCommit.maxTime", "-1");

    CoreContainer container = new CoreContainer(loader);
    container.load();

    SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()),
            ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);

    if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
        throw new UnsupportedOperationException(
                "Invalid configuration. Currently, the only DirectoryFactory supported is "
                        + HdfsDirectoryFactory.class.getSimpleName());
    }

    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
    return solr;
}

From source file:net.darkmist.alib.io.Serializer.java

/** Serializes an object to a temporary file.
 * @param obj The object to serialize.//from   w  ww .  j  a va  2  s  .  c  o  m
 * @return The file the object is serialized in. This file will already be set to be deleted on process exit.
 */
public static <T extends Serializable> File serializeToTempFile(T obj) throws IOException {
    File file = File.createTempFile(Serializer.class.getName().replace(".*\\.", ""), null);
    file.deleteOnExit();
    serializeToFile(obj, file);
    return file;
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.core.util.FileUtils.java

/**
 * Makes the given stream available as a file. The created file is temporary
 * and deleted upon normal termination of the JVM. Still the file should be
 * deleted as soon as possible if it is no longer required. In case the JVM
 * crashes the file would not be deleted. The source stream is closed by
 * this operation in all cases./*from   w w  w.  ja v a  2 s. c om*/
 *
 * @param is
 *            the source.
 * @return the file.
 * @throws IOException
 *             in case of read or write problems.
 */
public static File getStreamAsFile(final InputStream is) throws IOException {
    OutputStream os = null;
    try {
        final File f = File.createTempFile("dkpro_stream", "tmp");
        f.deleteOnExit();
        os = new FileOutputStream(f);
        IOUtils.copy(is, os);
        return f;
    } finally {
        IOUtils.closeQuietly(os);
        IOUtils.closeQuietly(is);
    }
}

From source file:eu.planets_project.services.datatypes.Content.java

/**
 * Create (streamed) content by reference, from an input stream.
 * @param inputStream The InputStream containing the value for the content.
 * @return A content instance with the specified value
 *//*from   w w  w  .  j  a  va2  s . c  o m*/
public static DigitalObjectContent byReference(final InputStream inputStream) {
    try {
        File tempFile = File.createTempFile("tempContent", "tmp");
        tempFile.deleteOnExit(); // TODO do we really want this here? 
        FileOutputStream out = new FileOutputStream(tempFile);
        IOUtils.copyLarge(inputStream, out);
        out.close();
        return new ImmutableContent(tempFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    throw new IllegalStateException("Could not create content for input stream: " + inputStream);
}

From source file:de.bund.bfr.pmfml.file.CombineArchiveUtil.java

static ArchiveEntry writeData(CombineArchive archive, NuMLDocument doc, String docName) throws IOException,
        TransformerFactoryConfigurationError, TransformerException, ParserConfigurationException {

    File tmpFile = File.createTempFile("tmp", ".numl");
    tmpFile.deleteOnExit();
    NuMLWriter.write(doc, tmpFile);/*from   ww w  .  j  a  va2  s.c o m*/
    return archive.addEntry(tmpFile, docName, URIS.numl);
}