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.thoughtworks.go.util.TestFileUtil.java

public static File createTestFile(File testFolder, String path) throws Exception {
    File subfile = new File(testFolder, path);
    subfile.createNewFile();/*from  ww w.  j a  v  a  2 s .com*/
    subfile.deleteOnExit();
    return subfile;
}

From source file:brut.util.Jar.java

public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException {
    try {//from   www.j  av  a  2s  . c o m
        InputStream in = Class.class.getResourceAsStream(resourcePath);
        if (in == null) {
            throw new FileNotFoundException(resourcePath);
        }
        File fileOut = File.createTempFile(tmpPrefix, null);
        fileOut.deleteOnExit();
        OutputStream out = new FileOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        return fileOut;
    } catch (IOException ex) {
        throw new BrutException("Could not extract resource: " + resourcePath, ex);
    }
}

From source file:com.liferay.portal.search.elasticsearch.internal.util.ResourceUtil.java

public static File getResourceAsTempFile(Class<?> clazz, String name) throws IOException {

    int index = name.lastIndexOf(CharPool.PERIOD);

    File file = File.createTempFile(name.substring(0, index), name.substring(index));

    file.deleteOnExit();

    try (InputStream inputStream = clazz.getResourceAsStream(name)) {
        FileUtils.copyInputStreamToFile(inputStream, file);
    }//from   ww  w .  ja  va2  s . co m

    return file;
}

From source file:com.technofovea.packbsp.PackbspUtil.java

/**
 * Efficiently copies a given file, returning a temporary copy which will be
 * removed when execution finishes.//  w  w w .ja va2 s.  co  m
 * 
 * @param source Source file to copy.
 * @return The copied file.
 * @throws IOException
 */
public static final File createTempCopy(File source) throws IOException {
    String ext = FilenameUtils.getExtension(source.getName());
    File dest = File.createTempFile("packbsp_temp_", "." + ext);
    dest.deleteOnExit();
    FileInputStream fis = new FileInputStream(source);
    FileOutputStream fos = new FileOutputStream(dest);
    IOUtils.copy(fis, fos);
    fis.close();
    fos.close();
    return dest;
}

From source file:jease.site.Streams.java

/**
 * Write given file to response./* w ww .  j a  v a 2s . co  m*/
 * 
 * If the given content type denotes a browser supported image, the image
 * will be automatically scaled if either "scale" is present as request
 * paramter or JEASE_IMAGE_LIMIT is set in Registry.
 */
public static void write(HttpServletRequest request, HttpServletResponse response, File file,
        String contentType) throws IOException {
    if (Images.isBrowserCompatible(contentType)) {
        int scale = NumberUtils.toInt(request.getParameter("scale"));
        if (scale > 0) {
            java.io.File scaledImage = Images.scale(file, scale);
            scaledImage.deleteOnExit();
            response.setContentType(contentType);
            response.setContentLength((int) scaledImage.length());
            Files.copy(scaledImage.toPath(), response.getOutputStream());
            return;
        }
        int limit = NumberUtils.toInt(Registry.getParameter(Names.JEASE_IMAGE_LIMIT));
        if (limit > 0) {
            java.io.File scaledImage = Images.limit(file, limit);
            scaledImage.deleteOnExit();
            response.setContentType(contentType);
            response.setContentLength((int) scaledImage.length());
            Files.copy(scaledImage.toPath(), response.getOutputStream());
            return;
        }

    }
    response.setContentType(contentType);
    response.setContentLength((int) file.length());
    Files.copy(file.toPath(), response.getOutputStream());
}

From source file:brut.androlib.mod.SmaliMod.java

public static boolean assembleSmaliFile(InputStream is, DexBuilder dexBuilder, boolean verboseErrors,
        boolean printTokens, File smaliFile) throws IOException, RecognitionException {

    // copy our filestream into a tmp file, so we don't overwrite
    File tmp = File.createTempFile("BRUT", ".bak");
    tmp.deleteOnExit();

    OutputStream os = new FileOutputStream(tmp);
    IOUtils.copy(is, os);/*w w w.j av a2  s . c  om*/
    os.close();

    return assembleSmaliFile(tmp, dexBuilder, verboseErrors, printTokens);
}

From source file:com.logsniffer.model.support.LineInputStreamTest.java

public static File writeString2Tmp(final String text, final String charset) throws IOException {
    File tmp = File.createTempFile("test", "txt");
    tmp.deleteOnExit();
    FileUtils.writeStringToFile(tmp, text, charset);
    return tmp;/*from w w w  . ja  v  a2 s .c  o m*/
}

From source file:org.slc.sli.ingestion.IngestionTest.java

public static File createTempFile(String prefix, String suffix) throws IOException {
    File file = File.createTempFile(prefix, suffix);
    file.deleteOnExit();
    return file;/*from w ww.j  a  va 2 s.  co m*/
}

From source file:com.amazonaws.services.kinesis.producer.KinesisProducerConfigurationTest.java

private static String writeFile(String contents) {
    try {//from  w ww . j  a  v a  2s  .c  o m
        File f = File.createTempFile(UUID.randomUUID().toString(), "");
        f.deleteOnExit();
        FileUtils.write(f, contents);
        return f.getAbsolutePath();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.milaboratory.core.io.util.TestUtil.java

public static File createRandomFile(long seed, int avLinesCount) throws IOException {
    File temp = File.createTempFile("temp" + seed, "tmp");
    temp.deleteOnExit();
    FileOutputStream output = new FileOutputStream(temp);
    Well1024a random = new Well1024a(seed);

    int numberOfLines = avLinesCount + random.nextInt(10);
    for (int i = 0; i < numberOfLines; ++i) {
        StringBuilder sb = new StringBuilder();
        for (int j = (1 + random.nextInt(100)); j >= 0; --j)
            sb.append(random.nextInt(100));
        String string = sb.toString();
        byte[] bytes = string.getBytes();
        output.write(bytes);//from  w  ww  .  j av  a 2  s  . c om
        output.write('\n');
    }
    output.close();
    return temp;
}