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.legstar.protobuf.cobol.ProtoCobolUtilsTest.java

public void testExtractPackageNameNoWhiteSpacesFromProtoFile() throws Exception {
    File protoFile = File.createTempFile(getName(), ".proto");
    protoFile.deleteOnExit();//  ww w  .  ja v a2 s.  c  o  m
    FileUtils.writeStringToFile(protoFile, "option java_package=\"com.example.tutorial\";");
    ProtoFileJavaProperties javaProperties = ProtoCobolUtils.getJavaProperties(protoFile);
    assertEquals("com.example.tutorial", javaProperties.getJavaPackageName());
}

From source file:com.streamsets.pipeline.stage.executor.shell.TestShellExecutor.java

@Before
public void setUp() throws Exception {
    this.config = new ShellConfig();
    this.handoverFile = File.createTempFile("handover-test", ".txt");
}

From source file:com.hortonworks.registries.util.HdfsFileStorageTest.java

@Test
public void testUploadJar() throws Exception {
    Map<String, String> config = new HashMap<>();
    config.put(HdfsFileStorage.CONFIG_FSURL, "file:///");
    fileStorage.init(config);/*from  ww w. j ava2 s.  com*/

    File file = File.createTempFile("test", ".tmp");
    file.deleteOnExit();

    List<String> lines = Arrays.asList("test-line-1", "test-line-2");
    Files.write(file.toPath(), lines, Charset.forName("UTF-8"));
    String jarFileName = "test.jar";

    fileStorage.deleteFile(jarFileName);

    fileStorage.uploadFile(new FileInputStream(file), jarFileName);

    InputStream inputStream = fileStorage.downloadFile(jarFileName);
    List<String> actual = IOUtils.readLines(inputStream);
    Assert.assertEquals(lines, actual);
}

From source file:com.eyeq.pivot4j.export.poi.FopExporterIT.java

@Test
public void testExportPdf() throws IOException {
    OutputStream out = null;/*from  w  w w.  j a  v a 2  s  .co  m*/

    File file = File.createTempFile("pivot4j-", ".pdf");

    if (deleteTestFile) {
        file.deleteOnExit();
    }

    try {
        out = new FileOutputStream(file);

        FopExporter exporter = new FopExporter(out);

        exporter.setShowParentMembers(true);
        exporter.setShowDimensionTitle(true);
        exporter.setHideSpans(false);
        exporter.setOrientation(OrientationRequested.LANDSCAPE);

        exporter.render(getPivotModel());
    } finally {
        out.flush();
        IOUtils.closeQuietly(out);
    }
}

From source file:io.fabric8.runsh.RunShLoaderTest.java

@Test
public void checkCopyScript() throws IOException {
    File dest = File.createTempFile("run", ".sh");
    RunShLoader.copyRunScript(dest);/*from   w  w  w. ja  v  a 2 s  . com*/
    String orig = RunShLoader.getRunScript();
    String copied = FileUtils.readFileToString(dest);
    assertEquals(orig, copied);
}

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

@Test(groups = "unit")
public void getOutputContext() throws IOException {
    final File file = File.createTempFile("tpxtst", "");
    try {/*from  w ww .  j a  v  a 2  s . c o m*/
        final TestStreamInputContextImpl context = new TestStreamInputContextImpl();
        context.bytes = "Moo Cow".getBytes();
        context.get(OutputContexts.forFile(file));
        assert org.apache.commons.io.FileUtils.readFileToString(file).equals("Moo Cow");
    } finally {
        file.delete();
    }
}

From source file:io.druid.data.input.impl.PrefetchableTextFilesFirehoseFactoryTest.java

@BeforeClass
public static void setup() throws IOException {
    testDir = File.createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(), "testDir");
    FileUtils.forceDelete(testDir);/*from  w ww . java 2 s.  c  o m*/
    FileUtils.forceMkdir(testDir);

    firehoseTempDir = File.createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(),
            "baseDir");
    FileUtils.forceDelete(firehoseTempDir);
    FileUtils.forceMkdir(firehoseTempDir);

    for (int i = 0; i < 10; i++) {
        // Each file is 1390 bytes
        try (final Writer writer = new BufferedWriter(new FileWriter(new File(testDir, "test_" + i)))) {
            for (int j = 0; j < 100; j++) {
                final String a = (20171220 + i) + "," + i + "," + j + "\n";
                writer.write(a);
            }
        }
    }
}

From source file:com.gooddata.gdc.DatastoreServiceAT.java

@Test(groups = "datastore", dependsOnMethods = "datastoreUpload")
public void datastoreDownload() throws Exception {
    DataStoreService dataStoreService = gd.getDataStoreService();

    final File file = File.createTempFile("file", ".txt");
    try (InputStream stream = dataStoreService.download(this.file)) {
        file.deleteOnExit();//from   w ww  .ja v a2  s.c  o m
        IOUtils.copy(stream, new FileOutputStream(file));
    } finally {
        file.delete();
    }
}

From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java

public void testTempClassLoader_getResource() throws Exception {

    File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile();
    File jar = File.createTempFile("testTempClassLoader_getClass", ".jar");
    jar.deleteOnExit();/*from  w ww . ja  v a 2  s.c  om*/
    FileUtils.copyFile(sourceJar, jar);

    try {
        ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar);
        InputStream is = ClassLoaderUtils.getResourceAsStream("foo/bar/baz/JarType.java", cl);
        assertNotNull(is);
        assertTrue(is.available() > 0);
        is.close();
    } finally {
        jar.delete();
    }
}

From source file:eu.scape_project.archiventory.container.ZipContainerTest.java

/**
 * Test of init method, of class ZipContainer.
 */// w  w w .  j a  v  a  2  s.c o  m
@Test
public void testInit() throws Exception {
    InputStream testFileStream = ZipContainer.class.getResourceAsStream("test.zip");
    if (testFileStream == null)
        fail();
    File tmpTestFile = File.createTempFile("test", ".zip");
    FileOutputStream fos = new FileOutputStream(tmpTestFile);
    IOUtils.copy(testFileStream, fos);
    fos.close();
    String containerFileName = "test.zip";
    InputStream containerFileStream = new FileInputStream(tmpTestFile);
    ZipContainer instance = new ZipContainer();
    instance.init(containerFileName, containerFileStream);
    DualHashBidiMap bidiIdentifierFilenameMap = instance.getBidiIdentifierFilenameMap();
    String key = instance.getExtractDirectoryName() + "test.zip/test.doc";
    assertTrue(bidiIdentifierFilenameMap.containsKey(key));
    String value = (String) bidiIdentifierFilenameMap.get(key);
    assertNotNull(value);
    File tmpFile = new File(value);
    assertTrue("File does not exist: " + tmpFile.getAbsolutePath(), tmpFile.exists());
}