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.aurel.track.dbase.InitReportTemplateBL.java

public static void addReportTemplates() {
    URL urlSrc;/*from   w w  w  . j a  v  a 2 s  .  co m*/
    File srcDir = null;
    //first try to get the template dir through class.getResource(path)
    urlSrc = PluginUtils.class.getResource("/resources/reportTemplates");
    urlSrc = PluginUtils.createValidFileURL(urlSrc);
    if (urlSrc != null) {
        LOGGER.info("Retrieving report templates from " + urlSrc.toString());
        srcDir = new File(urlSrc.getPath());
        Long uuid = new Date().getTime();
        File tmpDir = new File(
                System.getProperty("java.io.tmpdir") + File.separator + "TrackTmp" + uuid.toString());
        if (!tmpDir.isDirectory()) {
            tmpDir.mkdir();
        }
        tmpDir.deleteOnExit();

        File[] files = srcDir.listFiles(new InitReportTemplateBL.Filter());
        if (files == null || files.length == 0) {
            LOGGER.error("Problem unzipping report template: No files.");
            return;
        }
        for (int index = 0; index < files.length; index++) {
            ZipFile zipFile = null;
            try {
                String sname = files[index].getName();
                String oid = sname.substring(sname.length() - 6, sname.length() - 4);
                zipFile = new ZipFile(files[index], ZipFile.OPEN_READ);
                LOGGER.debug("Extracting template from " + files[index].getName());
                unzipFileIntoDirectory(zipFile, tmpDir);

                File descriptor = new File(tmpDir, "description.xml");
                InputStream in = new FileInputStream(descriptor);
                //parse using builder to get DOM representation of the XML file
                Map<String, Object> desc = ReportBL.getTemplateDescription(in);

                String rname = "The name";
                String description = "The description";
                String expfmt = (String) desc.get("format");

                Map<String, String> localizedStuff = (Map<String, String>) desc
                        .get("locale_" + Locale.getDefault().getLanguage());
                if (localizedStuff != null) {
                    rname = localizedStuff.get("listing");
                    description = localizedStuff.get("description");
                } else {
                    localizedStuff = (Map<String, String>) desc.get("locale_en");
                    rname = localizedStuff.get("listing");
                    description = localizedStuff.get("description");
                }

                addReportTemplateToDatabase(new Integer(oid), rname, expfmt, description);

            } catch (IOException e) {
                LOGGER.error("Problem unzipping report template " + files[index].getName());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
}

From source file:com.change_vision.astah.extension.plugin.csharpreverse.reverser.DoxygenXmlParser.java

/**
 * /*from   ww w.  ja  va  2  s .c  o  m*/
 * @return String
 * @throws IOException
 */
private static String getTempAstahModelPath() throws IOException {
    Calendar cal = Calendar.getInstance();
    String year = Integer.toString(cal.get(Calendar.YEAR));
    String month = Integer.toString(cal.get(Calendar.MONTH) + 1);
    String day = Integer.toString(cal.get(Calendar.DATE));
    String hour = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
    String minute = Integer.toString(cal.get(Calendar.MINUTE));
    String second = Integer.toString(cal.get(Calendar.SECOND));

    String tempFileName = year + month + day + hour + minute + second;
    File tempFile = File.createTempFile(tempFileName, ".asta");
    tempFile.deleteOnExit();
    return tempFile.getAbsolutePath();
}

From source file:net.sf.jasperreports.eclipse.util.FileUtils.java

public static File createTempFile(String prefix, String sufix) throws IOException {
    File f = File.createTempFile(prefix, sufix);
    f.deleteOnExit();
    return f;//from w ww .j  a  v  a  2 s.  c  om
}

From source file:de.uni.bremen.monty.moco.Main.java

private static File buildExecutable(String outputFileName, String inputFileName, boolean compileOnly,
        String llvmCode) throws IOException, InterruptedException {
    File outputFile = null;
    if (outputFileName != null) {
        outputFile = new File(outputFileName);
    } else if (inputFileName != null) {
        outputFile = new File(FilenameUtils.removeExtension(inputFileName));
    } else if (compileOnly) {
        outputFile = File.createTempFile("output", null, null);
        outputFile.deleteOnExit();
    } else {//w  ww.  j  a v  a 2s.c  o m
        outputFile = new File("output");
    }

    ProcessBuilder llcProcessBuilder = new ProcessBuilder("llc", "-O=2");
    Process llcProcess = llcProcessBuilder.start();
    PrintStream llcInput = new PrintStream(llcProcess.getOutputStream());
    llcInput.print(llvmCode);
    llcInput.close();

    ProcessBuilder ccProcessBuilder = new ProcessBuilder("cc", "-x", "assembler", "-o",
            outputFile.getAbsolutePath(), "-");
    Process ccProcess = ccProcessBuilder.start();
    IOUtils.copy(llcProcess.getInputStream(), ccProcess.getOutputStream());
    ccProcess.getOutputStream().close();

    System.err.print(IOUtils.toString(llcProcess.getErrorStream()));
    System.err.print(IOUtils.toString(ccProcess.getErrorStream()));
    return outputFile;
}

From source file:docs.AbstractGemFireIntegrationTests.java

protected static File writeProcessControlFile(File path) throws IOException {
    assertThat(path != null && path.isDirectory()).isTrue();

    File processControl = new File(path, DEFAULT_PROCESS_CONTROL_FILENAME);

    assertThat(processControl.createNewFile()).isTrue();

    processControl.deleteOnExit();

    return processControl;
}

From source file:ArchiveUtil.java

private static void extractEntry(File entryFile, JarInputStream jis, JarEntry entry, boolean deleteOnExit)
        throws IOException {
    File parent = new File(entryFile.getParent());
    if (!parent.exists())
        parent.mkdirs();/*from  w w  w. j  a v  a  2  s.co m*/
    ResourceUtil.copy(jis, new FileOutputStream(entryFile));
    entryFile.setLastModified(entry.getTime());
    if (deleteOnExit) {
        parent.deleteOnExit();
        entryFile.deleteOnExit();
    }
}

From source file:ffx.utilities.StringUtils.java

/**
 * Returns the file name of a temporary copy of <code>input</code> content.
 *
 * @param input a {@link java.io.InputStream} object.
 * @param name a {@link java.lang.String} object.
 * @param suffix a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 * @throws java.io.IOException if any./* ww w .java  2s.c o m*/
 */
public static String copyInputStreamToTmpFile(final InputStream input, String name, final String suffix)
        throws IOException {
    File tmpFile = null;
    try {
        name = "ffx." + name + ".";
        tmpFile = File.createTempFile(name, suffix);
    } catch (Exception e) {
        System.out.println(" Could not extract a Force Field X library.");
        System.err.println(e.toString());
        System.exit(-1);
    }

    tmpFile.deleteOnExit();
    OutputStream output = null;
    try {
        output = new BufferedOutputStream(new FileOutputStream(tmpFile));
        byte[] buffer = new byte[8192];
        int size;
        while ((size = input.read(buffer)) != -1) {
            output.write(buffer, 0, size);
        }
    } finally {
        if (input != null) {
            input.close();
        }
        if (output != null) {
            output.close();
        }
    }

    return tmpFile.toString();
}

From source file:fr.gouv.culture.vitam.droid.DroidHandler.java

public static final void cleanTempFiles() {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    File[] todelete = tmpDir.listFiles(new FileFilter() {

        @Override//from  w  w  w . j a  v a  2  s  .  c  o m
        public boolean accept(File arg0) {
            String name = arg0.getName();
            return (name.endsWith(".tmp")
                    && (name.startsWith(StaticValues.PREFIX_TEMPFILE) || name.startsWith("droid-archive")));
        }
    });
    for (File file : todelete) {
        if (!file.delete()) {
            file.deleteOnExit();
        }
    }
}

From source file:azkaban.project.FlowLoaderUtils.java

/**
 * Clean up the directory.//from  www  .  ja v  a  2  s .  c o  m
 *
 * @param dir the directory to be deleted
 */
public static void cleanUpDir(final File dir) {
    try {
        if (dir != null && dir.exists()) {
            FileUtils.deleteDirectory(dir);
        }
    } catch (final IOException e) {
        logger.error("Failed to delete the directory", e);
        dir.deleteOnExit();
    }
}

From source file:org.lol.reddit.common.General.java

public static void moveFile(final File src, final File dst) throws IOException {

    if (!src.renameTo(dst)) {

        copyFile(src, dst);//  www . j a  v  a 2  s  .c om

        if (!src.delete()) {
            src.deleteOnExit();
        }
    }
}