Example usage for java.io File createTempFile

List of usage examples for java.io File createTempFile

Introduction

In this page you can find the example usage for java.io File createTempFile.

Prototype

public static File createTempFile(String prefix, String suffix) throws IOException 

Source Link

Document

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

Usage

From source file:com.adobe.ac.pmd.engines.AbstractFlexPmdEngine.java

private static File extractDefaultRuleSet() throws URISyntaxException, IOException {
    final String rulesetURI = "/com/adobe/ac/pmd/default_flex.xml";
    final InputStream resourceAsStream = AbstractFlexPmdEngine.class.getResourceAsStream(rulesetURI);
    final File temporaryRuleset = File.createTempFile("default_flex", ".xml");
    temporaryRuleset.deleteOnExit();/*  w w  w  .j a  va  2s . com*/
    final FileOutputStream writter = new FileOutputStream(temporaryRuleset);
    IOUtil.copy(resourceAsStream, writter);

    resourceAsStream.close();
    return temporaryRuleset;
}

From source file:edu.umn.msi.tropix.common.io.FileFunctionsTest.java

@Test(groups = "unit")
public void getInputStreamFunction() throws IOException {
    final File file = File.createTempFile("tpxtst", "");
    try {/*from w  ww. j a  v a 2  s  .c om*/
        org.apache.commons.io.FileUtils.writeStringToFile(file, "Moo Cow");
        final InputStream stream = FileFunctions.getInputStreamFunction().apply(file);
        assert org.apache.commons.io.IOUtils.toString(stream).equals("Moo Cow");
    } finally {
        file.delete();
    }
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java

public static File compressFile(final String projectName, final Path pathToCompress,
        final CompressionType compressionType, final BuildListener listener) throws IOException {
    File compressedArtifacts = null;

    try {/*w w  w  .  ja va  2s .c  o m*/
        switch (compressionType) {
        case Zip:
            compressedArtifacts = File.createTempFile(projectName + "-", ".zip");
            compressZipFile(compressedArtifacts, pathToCompress, listener);
            break;
        case Tar:
            compressedArtifacts = File.createTempFile(projectName + "-", ".tar");
            compressTarFile(compressedArtifacts, pathToCompress, listener);
            break;
        case TarGz:
            compressedArtifacts = File.createTempFile(projectName + "-", ".tar.gz");
            compressTarGzFile(compressedArtifacts, pathToCompress, listener);
            break;
        case None:
            throw new IllegalArgumentException("No compression type specified.");
        }
    } catch (final IOException e) {
        if (compressedArtifacts != null) {
            if (!compressedArtifacts.delete()) {
                compressedArtifacts.deleteOnExit();
            }
        }
        throw e;
    }

    return compressedArtifacts;
}

From source file:FileUtil.java

/**
 *  Makes a new temporary file and writes content into it. The temporary
 *  file is created using <code>File.createTempFile()</code>, and the usual
 *  semantics apply.  The files are not deleted automatically in exit.
 *
 *  @param content Initial content of the temporary file.
 *  @param encoding Encoding to use./* www  .  j ava 2  s  .c o  m*/
 *  @return The handle to the new temporary file
 *  @throws IOException If the content creation failed.
 *  @see java.io.File#createTempFile(String,String,File)
 */
public static File newTmpFile(String content, String encoding) throws IOException {
    Writer out = null;
    Reader in = null;
    File f = null;

    try {
        f = File.createTempFile("jspwiki", null);

        in = new StringReader(content);

        out = new OutputStreamWriter(new FileOutputStream(f), encoding);

        copyContents(in, out);
    } finally {
        if (in != null)
            in.close();
        if (out != null)
            out.close();
    }

    return f;
}

From source file:com.xclinical.mdr.server.impexp.ZipResourceResolver.java

public ZipResourceResolver(InputStream stm) throws IOException {
    File file = File.createTempFile("mdrres", ".tmp");
    FileOutputStream out = new FileOutputStream(file);
    Streams.copy(stm, out, true);/*  ww w . j ava 2 s  .  c o  m*/
    this.file = new ZipFile(file);
}

From source file:com.switchfly.compress.cli.CompressCLITest.java

@Before
public void setUp() throws Exception {

    _inputLocation = new File(getClass().getResource("asset_packages.yml").getFile()).getParentFile();

    _outputLocation = File.createTempFile("output_", "_TEST");
    if (_outputLocation.exists()) {
        _outputLocation.delete();//from w  w  w.  ja  v a2s .c o m
    }
    _outputLocation.mkdir();

    _outputFile = File.createTempFile("output_", "_compressed");
    FileUtils.deleteQuietly(_outputFile);

    _configuration = FileUtils
            .readFileToString(new File(getClass().getResource("asset_packages.yml").getFile()));
}

From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AnsibleVaultTest.java

@BeforeEach
public void setUp() throws Exception {
    testFile = File.createTempFile(getClass().getName(), null);

    System.setProperty(AnsibleVaultPassword.SYSTEM_PROPERTY_PASSWORD, "test123");
}

From source file:com.googlecode.t7mp.util.CommonsSetupUtilTest.java

@Before
public void setUp() throws IOException {
    catalinaBaseDir = Files.createTempDir();

    source = File.createTempFile("source", ".tmp");
    source.deleteOnExit();/*  ww w.j  a v a  2s.c o  m*/
    target = File.createTempFile("target", ".tmp");
    target.deleteOnExit();
    FileWriter sourceWriter = new FileWriter(source);
    sourceWriter.write(MESSAGE);
    sourceWriter.close();
}

From source file:com.intropro.prairie.format.seq.SequenceFormatWriter.java

@Override
public void write(String line) throws IOException {
    if (writer == null) {
        tmpFile = File.createTempFile("seq-", ".dat");
        writer = SequenceFile.createWriter(new Configuration(), Writer.file(new Path(tmpFile.toURI())),
                Writer.keyClass(NullWritable.class), Writer.valueClass(Text.class));
    }/* w  ww.j a  v  a  2 s.com*/
    text.set(line);
    writer.append(NullWritable.get(), text);
}

From source file:gov.nih.nci.caarray.services.external.v1_0.data.AbstractDataApiUtils.java

/**
 * {@inheritDoc}//from ww w  . j  a v  a 2s .co  m
 */
public File downloadFileContentsToTempFile(CaArrayEntityReference fileRef, boolean compressed)
        throws InvalidReferenceException, DataTransferException, IOException {
    File tempFile = File.createTempFile("retrievedFile", null);
    downloadFileContentsToFile(fileRef, compressed, tempFile);
    return tempFile;
}