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:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.CryptoKeysTest.java

@BeforeEach
public void setUp() throws Exception {
    // create temp directory path
    targetFolder = File.createTempFile(getClass().getName(), null);
    targetFolder.delete();/*from  w  w w.  j av a2 s .  c om*/

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

From source file:hudson.maven.settings.SettingsProviderUtils.java

/**
 * /*from  w w  w . ja va 2  s .c o m*/
 * @param config
 * @param workspace
 */
public static FilePath copyConfigContentToFilePath(Config config, FilePath workspace)
        throws IOException, InterruptedException {
    File tmpContentFile = null;
    ByteArrayInputStream bs = null;

    try {
        tmpContentFile = File.createTempFile("config", "tmp");
        FilePath filePath = new FilePath(workspace, tmpContentFile.getName());
        bs = new ByteArrayInputStream(config.content.getBytes());
        filePath.copyFrom(bs);
        return filePath;
    } finally {
        FileUtils.deleteQuietly(tmpContentFile);
        IOUtils.closeQuietly(bs);
    }
}

From source file:com.stratio.ingestion.morphline.commons.ContainsAnyOfTest.java

protected Config parse(String file, Config... overrides) throws IOException {
    File tmpFile = File.createTempFile("morphlines_", ".conf");
    IOUtils.copy(getClass().getResourceAsStream(file), new FileOutputStream(tmpFile));
    Config config = new org.kitesdk.morphline.base.Compiler().parse(tmpFile, overrides);
    config = config.getConfigList("morphlines").get(0);
    Preconditions.checkNotNull(config);//from w ww .j a v  a 2 s. co  m
    return config;
}

From source file:com.twitter.heron.common.config.SystemConfigTest.java

@Test
public void testReadConfig() throws IOException {
    InputStream inputStream = getClass().getResourceAsStream(RESOURCE_LOC);
    if (inputStream == null) {
        throw new RuntimeException("Sample output file not found");
    }//from  w  ww  .ja v  a 2 s.  c om
    File file = File.createTempFile("system_temp", "yaml");
    file.deleteOnExit();
    OutputStream outputStream = new FileOutputStream(file);
    IOUtils.copy(inputStream, outputStream);
    outputStream.close();
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(file.getAbsolutePath(), true).build();
    Assert.assertEquals("log-files", systemConfig.getHeronLoggingDirectory());
    Assert.assertEquals(ByteAmount.fromMegabytes(100), systemConfig.getHeronLoggingMaximumSize());
    Assert.assertEquals(5, systemConfig.getHeronLoggingMaximumFiles());
    Assert.assertEquals(Duration.ofSeconds(60), systemConfig.getHeronMetricsExportInterval());
}

From source file:com.hp.alm.ali.idea.progress.IndicatingOutputStreamTest.java

@Before
public void preClean() throws IOException {
    file = File.createTempFile("test", "");
    file.deleteOnExit();
}

From source file:com.atlassian.jira.webtests.ztests.admin.TestImportExport.java

public void testXmlImportFromNonImportDirectory() throws Exception {
    File data = new File(getEnvironmentData().getXMLDataLocation(), "EmptyJira.xml");

    // write new data to temp file
    File newData = File.createTempFile("testXmlImportFromNonImportDirectory", ".xml"); //This will be created in the /tmp directory
    try {//  w w  w .  j a  va2s. c  o m
        FileUtils.copyFile(data, newData);

        tester.gotoPage("secure/admin/XmlRestore!default.jspa");
        tester.setWorkingForm("restore-xml-data-backup");
        tester.setFormElement("filename", newData.getAbsolutePath());
        tester.submit();

        tester.assertTextPresent("Could not find file at this location");
    } finally {
        newData.delete();
    }
}

From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java

public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException {
    if (!logFile.exists()) {
        throw new FileNotFoundException();
    }// w w  w .j  av a  2  s  .  c  o m

    File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip");

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile);
    zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
    zipOutputStream.setEncoding(ZIP_ENCODING);

    ArchiveEntry archiveEntry = newArchive(logFile);
    zipOutputStream.putArchiveEntry(archiveEntry);

    FileInputStream logFileInput = new FileInputStream(logFile);
    IOUtils.copyLarge(logFileInput, zipOutputStream);

    logFileInput.close();

    zipOutputStream.closeArchiveEntry();
    zipOutputStream.close();

    FileInputStream tempFileInput = new FileInputStream(tempFile);
    IOUtils.copyLarge(tempFileInput, outputStream);

    tempFileInput.close();

    FileUtils.deleteQuietly(tempFile);
}

From source file:cc.recommenders.io.IoUtilsTest.java

@Test
public void randomDirIsSubfolderOfTmp() throws IOException {
    URL actual = sut.getRandomTempDirectory().getUrl();
    URL expected = File.createTempFile(IoUtils.TEMP_PREFIX, "").toURI().toURL();

    int len = expected.toString().indexOf(IoUtils.TEMP_PREFIX);

    String actual2 = actual.toString().substring(0, len);
    String expected2 = expected.toString().substring(0, len);

    assertEquals(expected2, actual2);//from  w w  w.j  a v a2 s.  c  o m
}

From source file:com.xebialabs.deployit.cli.ext.mustachify.io.Files2.java

/**
 * Returns the path to an (almost certainly) non-existent file in the default temporary 
 * directory. The file itself is <em>not</em> created.
 * //from   www  . ja va  2  s.  c  o  m
 * Due to the small possibility that another process claims the name before it can
 * be used, callers may wish to check for existence using {@link File#exists()} to
 * be sure.
 */
public static String getTempFilePath(String basename, String ext) throws IOException {
    File tempFile = File.createTempFile(basename, ext);
    String tempFilePath = tempFile.getPath();
    tempFile.delete();
    return tempFilePath;
}

From source file:com.milaboratory.core.io.sequence.fasta.FastaWriterTest.java

@Test
public void test1() throws Exception {
    int count = 100;
    SingleRead[] reads = new SingleRead[count];
    File temp = File.createTempFile("temp", ".fasta");
    temp.deleteOnExit();/*  w  w w.j a va2 s  .  co  m*/
    FastaWriter writer = new FastaWriter(temp, 50);
    for (int i = 0; i < count; ++i) {
        reads[i] = randomRead(i);
        writer.write(reads[i]);
    }
    writer.close();
    FastaReader reader = new FastaReader(temp, false);
    for (int i = 0; i < count; ++i) {
        SingleRead actual = reader.take();
        Assert.assertEquals(reads[i].getDescription(), actual.getDescription());
        Assert.assertEquals(reads[i].getData(), actual.getData());
    }
    Assert.assertTrue(reader.take() == null);
    reader.close();
    temp.delete();
}