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.adaptris.core.runtime.MessageDigestErrorEntryTest.java

private File deleteLater(Object marker) throws IOException {
    File f = File.createTempFile(this.getClass().getSimpleName(), "");
    f.deleteOnExit();
    cleaner.track(f, marker, FileDeleteStrategy.FORCE);
    return f;/*from w  w  w . j  ava 2s .  c  om*/
}

From source file:io.apiman.manager.api.migrator.DataMigratorTest.java

private void doTest(String fileToMigrate, String expectedResultFile, String versionToMigrateTo)
        throws Exception {
    Version version = new Version();
    setVersion(version, versionToMigrateTo);
    StringBuilderLogger logger = new StringBuilderLogger();

    File tempOutputFile = File.createTempFile("_apiman", "tst");
    tempOutputFile.deleteOnExit();

    try {//from  www .  ja  v a 2s  .  com
        DataMigrator migrator = new DataMigrator();
        migrator.setLogger(logger);
        migrator.setVersion(version);

        InputStream input = getClass().getClassLoader().getResourceAsStream(fileToMigrate);
        OutputStream output = new FileOutputStream(tempOutputFile);

        // Migrate the data!
        migrator.migrate(input, output);

        JsonCompare compare = new JsonCompare();
        compare.setArrayOrdering(JsonArrayOrderingType.strict);
        compare.setIgnoreCase(false);
        compare.setMissingField(JsonMissingFieldType.fail);
        try (FileInputStream actual = new FileInputStream(tempOutputFile);
                InputStream expected = getClass().getClassLoader().getResourceAsStream(expectedResultFile);) {
            compare.assertJson(expected, actual);
        }
    } finally {
        FileUtils.deleteQuietly(tempOutputFile);
    }
}

From source file:net.sf.keystore_explorer.gui.dnd.KeyStoreEntryTransferable.java

/**
 * Get transfer data./*from ww w .  j a  va2s.  com*/
 *
 * @param dataFlavor
 *            Data flavor
 * @return Transfer data
 * @throws UnsupportedFlavorException
 *             If the requested data flavor is not supported
 * @throws IOException
 *             If an I/O problem occurred
 */
@Override
public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(dataFlavor)) {
        throw new UnsupportedFlavorException(dataFlavor);
    }

    if (dataFlavor == DataFlavor.javaFileListFlavor) {
        String tempDir = System.getProperty("java.io.tmpdir");

        File tmpFile = new File(tempDir, dragEntry.getFileName());
        tmpFile.deleteOnExit();

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(tmpFile);
            fos.write(dragEntry.getContent());
        } finally {
            IOUtils.closeQuietly(fos);
        }

        List<File> list = new ArrayList<File>();
        list.add(tmpFile);
        return list;
    } else {
        return dragEntry.getContentString();
    }
}

From source file:com.hortonworks.streamline.streams.catalog.configuration.ConfigFileWriterTest.java

@Test(expected = IllegalArgumentException.class)
public void writeUnknownTypeConfigToFile() throws Exception {
    Map<String, String> configuration = createDummyConfiguration();

    File destPath = Files.createTempFile("config", "unknown").toFile();
    destPath.deleteOnExit();

    writer.writeConfigToFile(null, configuration, destPath);
    fail("It shouldn't reach here.");
}

From source file:com.playonlinux.core.utils.archive.TarTest.java

@Test(expected = ArchiveException.class)
public void testBunzip2_extractGzip() throws IOException {
    final File inputFile = new File(inputUrl.getPath(), "pol.txt.gz");
    final File outputFile = File.createTempFile("output", "txt");
    outputFile.deleteOnExit();
    new Tar().bunzip2(inputFile, outputFile);
}

From source file:com.playonlinux.core.utils.archive.TarTest.java

@Test(expected = ArchiveException.class)
public void tesGunzip_extractBzip2() throws IOException {
    final File inputFile = new File(inputUrl.getPath(), "pol.txt.bz2");
    final File outputFile = File.createTempFile("output", "txt");
    outputFile.deleteOnExit();
    new Tar().gunzip(inputFile, outputFile);

}

From source file:com.googlecode.fascinator.indexer.RuleManager.java

private File createTempFile(String prefix, String postfix) throws IOException {
    File tempFile = File.createTempFile(prefix, postfix, workDir);
    tempFile.deleteOnExit();
    if (tempFiles == null) {
        tempFiles = Collections.synchronizedList(new ArrayList<File>());
    }//  w w w.  ja v  a 2s .com
    tempFiles.add(tempFile);
    return tempFile;
}

From source file:com.liferay.util.servlet.fileupload.LiferayFileItem.java

protected File getTempFile() {
    String tempFileName = "upload_" + _getUniqueId();

    String extension = getFileNameExtension();

    if (extension != null) {
        tempFileName += "." + extension;
    }//from  w  w w  . j  a  v  a2 s  .c  o m

    File tempFile = new File(_repository, tempFileName);

    tempFile.deleteOnExit();

    return tempFile;
}

From source file:edu.scripps.fl.pipeline.DocumentStage.java

@Override
public void innerProcess(Object obj) throws StageException {
    File file = (File) obj;
    try {//from  w  w w. j  a v a  2  s  .co m
        Document document = EUtilsWebSession.getInstance().getDocument(new FileInputStream(file));
        file.deleteOnExit();
        emit(document);
    } catch (Exception ex) {
        log.error(String.format("Problem with file %s: %s", file, ex.getMessage()));
        throw new StageException(this, ex);
    }
}