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:de.cebitec.mgx.seqstorage.ReaderFactoryTest.java

private static File copyTestData(Class clazz, String uri, File targetDir, String targetName) throws Exception {
    File f = new File(targetDir.getAbsolutePath() + File.separator + targetName);
    try (BufferedInputStream is = new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(uri))) {
        f.deleteOnExit();
        try (FileOutputStream fos = new FileOutputStream(f)) {
            byte[] buffer = new byte[1024];
            int bytesRead = is.read(buffer);
            while (bytesRead >= 0) {
                fos.write(buffer, 0, bytesRead);
                bytesRead = is.read(buffer);
            }// w  w w. j  a v a2  s  .  com
        }
    }
    return f;
}

From source file:com.symbian.driver.core.cmdline.CleanCmdLine.java

/**
 * Fix DEF130053. add code to clean testdriver logs at current dir 
 *///  w w w  .j av a  2 s. co  m
private static void cleanLogs() {
    Pattern p = Pattern.compile("TestDriver\\d_\\d.log");

    File currentDir = new File(".");
    for (File file : currentDir.listFiles()) {
        if (p.matcher(file.getName()).matches()) {
            //it is testdriver log file, delete it
            file.deleteOnExit();
        }
    }
}

From source file:com.greenpepper.server.license.LicenceGenerator.java

private static void buildAcademic() throws Exception {
    File file = File.createTempFile("academic", ".lic");
    License license = License.academic("My School", _2006, _2006);
    LicenseManager lm = new LicenseManager(getLicenseParam());
    lm.store(license, file);//from   w  w  w.  ja va2 s  .co m
    if (deleteFiles)
        file.deleteOnExit();
    System.out.println("# Academic");
    System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file))));
    System.out.println("");
}

From source file:com.cloudera.director.aws.ec2.ebs.EBSMetadata.java

/**
 * Gets an instance of this class that uses only the given ebs metadata.
 *
 * @param metadata            map of ebs volume type to it's associated metadata
 * @param localizationContext the localization context
 * @return new ebs metadata object//from   www  .ja  v  a 2s  . co m
 */
public static EBSMetadata getDefaultInstance(final Map<String, String> metadata,
        LocalizationContext localizationContext) {
    PropertyResolver ebsMetadataResolver = PropertyResolvers.newMapPropertyResolver(metadata);
    File tempDir = Files.createTempDir();
    tempDir.deleteOnExit();
    EBSMetadataConfigProperties ebsMetadataConfigProperties = new EBSMetadataConfigProperties(
            new SimpleConfiguration(), tempDir, localizationContext);
    return new EBSMetadata(ebsMetadataConfigProperties, ebsMetadataResolver);
}

From source file:common.UglyLaunchTempPatch.java

/**
 * code for lunching external jar file//from  w w w. j  a  v a2 s  .  c  om
 * 
 * @param jarFile
 *            the jar file that is being lunched
 * @param Server
 *            is this a server lunch or not
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws InterruptedException
 */
public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException,
        InvocationTargetException, IllegalAccessException, InterruptedException {

    Main.print("\"" + jarFile.getAbsolutePath() + "\"");
    // sets jar to deleate on exit of program
    jarFile.deleteOnExit();

    //runs the client version of the forge installer.

    Map map = new HashMap();
    map.put("file", jarFile);
    CommandLine cmdLine = new CommandLine("java");
    cmdLine.addArgument("-jar");
    cmdLine.addArgument("${file}");
    cmdLine.setSubstitutionMap(map);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
    executor.setWatchdog(watchdog);
    int exitValue = executor.execute(cmdLine);
}

From source file:client.UglyLaunchTempPatch.java

/**
 * code for lunching external jar file/*from  w w  w. j a v  a2 s. c o m*/
 * 
 * @param jarFile
 *            the jar file that is being lunched
 * @param Server
 *            is this a server lunch or not
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws InterruptedException
 */
public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException,
        InvocationTargetException, IllegalAccessException, InterruptedException {

    main.print("\"" + jarFile.getAbsolutePath() + "\"");
    // sets jar to deleate on exit of program
    jarFile.deleteOnExit();

    //runs the client version of the forge installer.

    Map map = new HashMap();
    map.put("file", jarFile);
    CommandLine cmdLine = new CommandLine("java");
    cmdLine.addArgument("-jar");
    cmdLine.addArgument("${file}");
    cmdLine.setSubstitutionMap(map);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
    executor.setWatchdog(watchdog);
    int exitValue = executor.execute(cmdLine);
}

From source file:com.tesora.dve.common.PEBaseTest.java

/**
 * Creates a new randomly named directory in the default temporary-file directory.
 * The directory gets deleted when the virtual machine terminates.
 *///from  www.  ja va 2 s  .  c  o  m
protected static File getTemporaryDirectory() throws IOException {
    final File temp = Files.createTempDirectory(null).toFile();
    temp.deleteOnExit();
    return temp;
}

From source file:com.greenpepper.server.license.LicenceGenerator.java

private static void buildOpenSource() throws Exception {
    File file = File.createTempFile("opensource", ".lic");
    License license = License.openSource("My Open Source Project", _2006, _2006);
    LicenseManager lm = new LicenseManager(getLicenseParam());
    lm.store(license, file);// ww w  . ja  va2 s. co m
    if (deleteFiles)
        file.deleteOnExit();
    System.out.println("# Open source");
    System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file))));
    System.out.println("");
}

From source file:com.greenpepper.server.license.LicenceGenerator.java

private static void buildEvaluation(Date experyDate) throws Exception {
    File file = File.createTempFile("evaluation", ".lic");
    License license = License.evaluation("Some peeps evaluating", _2006, experyDate);
    LicenseManager lm = new LicenseManager(getLicenseParam());
    lm.store(license, file);/*w  ww.  jav  a  2 s .  c o  m*/
    if (deleteFiles)
        file.deleteOnExit();
    System.out.println("# Evaluation Expery: " + new FormatedDate(experyDate).getFormatedDate());
    System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file))));
    System.out.println("");
}

From source file:com.machinepublishers.jbrowserdriver.ResponseHandler.java

private static void writeContentToDisk(byte[] content, File dir, String url, String contentType,
        String contentDisposition) {
    String filename = Util.randomFileName();

    File contentFile = new File(dir, new StringBuilder().append(filename).append(".content").toString());

    File metaFile = new File(dir, new StringBuilder().append(filename).append(".metadata").toString());

    contentFile.deleteOnExit();
    metaFile.deleteOnExit();/*from   w w  w  .  ja v  a2s  .co  m*/

    try {
        Files.write(contentFile.toPath(), content);
        Files.write(metaFile.toPath(),
                (new StringBuilder().append(StringUtils.isEmpty(url) ? "" : url).append("\n")
                        .append(StringUtils.isEmpty(contentType) ? "" : contentType).append("\n")
                        .append(StringUtils.isEmpty(contentDisposition) ? "" : contentDisposition).toString())
                                .getBytes("utf-8"));
    } catch (Throwable t) {
    }
}