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:pl.altkom.spring.batch.ExcelExporterTest.java

@Test
public void test() throws IOException {

    List<Customer> list = dao.findAll();

    ExcelExporter exp = new ExcelExporter("raport");

    exp.addColumn(new ColumnDescriptor("Nazwisko i imi", "name"));
    exp.addColumn(new ColumnDescriptor("NIP", "nip"));
    exp.addColumn(new ColumnDescriptor("Ulica", "address.street"));

    for (Customer c : list) {
        exp.createRow(c);/*www .j a  v a  2s. c  om*/
    }

    File file = File.createTempFile("export", ".xls");

    System.out.println(file);

    exp.autoSizeAllColumns();
    exp.save(file);

}

From source file:com.sap.prd.mobile.ios.mios.PListAccessorTest.java

private File createTempFile() throws IOException {
    File temp = File.createTempFile("Info", ".plist");
    temp.deleteOnExit();/*  w  ww . ja  va  2  s.  c o m*/
    return temp;
}

From source file:com.meltmedia.cadmium.cli.BranchCreator.java

/**
 * Creates a temporary directory with a cloned remote git repository in it.
 * /*from w w  w.j  av a 2 s  .c  om*/
 * @param repoUri The git repository uri.
 * @throws Exception Thrown if the clone fails.
 */
public BranchCreator(String repoUri) throws Exception {
    tmpRepoLocal = File.createTempFile("tmpClone", ".git");
    if (tmpRepoLocal.delete()) {
        clonedRemote = GitService.cloneRepo(repoUri, tmpRepoLocal.getAbsoluteFile().getAbsolutePath());
    } else {
        System.err.println("ERROR: Failed to delete tmp file.");
    }

    if (clonedRemote == null) {
        throw new Exception("Failed to clone remote git repository @ " + repoUri);
    }
}

From source file:com.arpnetworking.tsdcore.sinks.FileSinkTest.java

@Before
public void before() throws IOException {
    _outFile = File.createTempFile("file-sink-test", ".out");
    _fileSinkBuilder = new FileSink.Builder().setName("file_sink_test").setFileName(_outFile.getAbsolutePath());
}

From source file:gov.nih.nci.caarray.plugins.agilent.EndOfLineCorrectingReaderTest.java

private File createTestFile() throws IOException {
    File file = File.createTempFile("EndOfLineCorrectingReaderTest", null);
    file.deleteOnExit();//w  w w .ja v a 2  s.c  o m

    final FileWriter fileWriter = new FileWriter(file);
    try {
        IOUtils.copy(new StringReader(originalData), fileWriter);
    } finally {
        fileWriter.close();
    }

    return file;
}

From source file:com.abstratt.graphviz.GraphViz.java

public static void generate(final InputStream input, String format, int dimensionX, int dimensionY,
        IPath outputLocation) throws CoreException {
    MultiStatus status = new MultiStatus(GraphVizActivator.ID, 0, "Errors occurred while running Graphviz",
            null);//from  w ww . j av  a  2s. c om
    File dotInput = null, dotOutput = outputLocation.toFile();
    // we keep the input in memory so we can include it in error messages
    ByteArrayOutputStream dotContents = new ByteArrayOutputStream();
    try {
        // determine the temp input location
        dotInput = File.createTempFile(TMP_FILE_PREFIX, DOT_EXTENSION);
        // dump the contents from the input stream into the temporary file
        // to be submitted to dot
        FileOutputStream tmpDotOutputStream = null;
        try {
            IOUtils.copy(input, dotContents);
            tmpDotOutputStream = new FileOutputStream(dotInput);
            IOUtils.copy(new ByteArrayInputStream(dotContents.toByteArray()), tmpDotOutputStream);
        } finally {
            IOUtils.closeQuietly(tmpDotOutputStream);
        }
        IStatus result = runDot(format, dimensionX, dimensionY, dotInput, dotOutput);
        if (dotOutput.isFile() && dotOutput.length() > 0) {
            if (!result.isOK() && Platform.inDebugMode())
                LogUtils.log(status);
            // success!
            return;
        }
    } catch (IOException e) {
        status.add(new Status(IStatus.ERROR, GraphVizActivator.ID, "", e));
    } finally {
        dotInput.delete();
        IOUtils.closeQuietly(input);
    }
    throw new CoreException(status);
}

From source file:com.logsniffer.model.file.WildcardLogSourceTest.java

@Test
public void testLogsResolving() throws IOException {
    File tmp = File.createTempFile("sdkj", "jk");
    tmp.deleteOnExit();/*from   www .  jav  a  2 s.c  om*/
    File tmpFolder1 = new File(tmp.getPath() + "d", "f1");
    tmpFolder1.mkdirs();
    tmpFolder1.deleteOnExit();
    File tmpFolder2 = new File(tmp.getPath() + "d", "f2");
    tmpFolder2.mkdirs();
    tmpFolder2.deleteOnExit();
    FileUtils.write(new File(tmpFolder1, "1.txt"), "txt");
    FileUtils.write(new File(tmpFolder1, "2.txt"), "txt");
    FileUtils.write(new File(tmpFolder1, "3.log"), "log");
    FileUtils.write(new File(tmpFolder2, "22.txt"), "txt");
    File tmpDir = new File(tmpFolder2, "folder.txt");
    tmpDir.mkdir();
    tmpDir.deleteOnExit();

    // Check now
    WildcardLogsSource source = new WildcardLogsSource();
    source.setPattern(tmp.getPath() + "d/*.txt");
    Assert.assertEquals(0, source.getLogs().size());
    source.setPattern(tmp.getPath() + "d/**/*.txt");
    Log[] logs = source.getLogs().toArray(new Log[0]);
    Assert.assertEquals(3, logs.length);
    Arrays.sort(logs, new Comparator<Log>() {
        @Override
        public int compare(final Log o1, final Log o2) {
            return o1.getPath().compareTo(o2.getPath());
        }
    });
    Assert.assertTrue(logs[0].getPath().endsWith("1.txt"));
    Assert.assertTrue(logs[1].getPath().endsWith("2.txt"));
    Assert.assertTrue(logs[2].getPath().endsWith("22.txt"));
}

From source file:com.strandls.alchemy.rest.client.stubgenerator.ProxyImplementationGeneratorTest.java

/**
 * Test method for/*from  w  w w .j a v  a2 s  .c o m*/
 * {@link com.strandls.alchemy.rest.client.stubgenerator.ProxyImplementationGenerator#generateProxy(java.lang.String, java.lang.String, java.lang.String, java.io.File)}
 * .
 *
 * @throws IOException
 */
@Test
public void testGenerateProxy() throws IOException {
    final ProxyImplementationGenerator generator = new ProxyImplementationGenerator();
    final File tempDir = File.createTempFile("test", "test");
    FileUtils.deleteQuietly(tempDir);

    if (!tempDir.mkdirs()) {
        throw new IOException("Cannot create temporary directory.");
    }
    try {
        generator.generateProxy("TestStub", "TestStubProxy", "", tempDir);
        assertEquals(
                FileUtils.readFileToString(
                        new File("src/test/resources/com/strandls/alchemy/rest/client/stubgenerator"
                                + "/TestStubProxy.txt"))
                        .trim(),
                FileUtils.readFileToString(new File(tempDir, "TestStubProxy.java")).trim());
    } finally {
        FileUtils.deleteQuietly(tempDir);
    }
}

From source file:edu.scripps.fl.pubchem.app.summary.ESummaryStage.java

@Override
public void innerProcess(Object obj) throws StageException {
    try {//from   w  w  w  .  j  a  va  2s  .c o  m
        Thread.sleep(333);
        List<Long> aids = (List<Long>) obj;
        InputStream in = EUtilsWebSession.getInstance().getSummaries(aids, "pcassay");
        File file = File.createTempFile("pubchem", "summary.xml");
        log.info(String.format("Downloaded %s summaries to %s", aids.size(), file));
        IOUtils.copy(in, new FileOutputStream(file));
        emit(file);
    } catch (Exception ex) {
        throw new StageException(this, ex);
    }
}

From source file:com.adaptris.fs.NioWorkerTest.java

@Test
public void testLockWhileWriting() throws Exception {
    NioWorker worker = createWorker();// w  ww. j av  a  2s  . com
    File f = File.createTempFile(this.getClass().getSimpleName(), "");
    f.delete();
    try {
        RandomAccessFile raf = new RandomAccessFile(f, "rwd");
        FileLock lock = raf.getChannel().lock();
        try {
            // Use the write method, because this "bypasses" the file.exists() check
            worker.write(BYTES, f);
            fail();
        } catch (FsException expected) {
            assertEquals(OverlappingFileLockException.class, expected.getCause().getClass());
        }
        lock.release();
        raf.close();
        f.delete();
        worker.put(BYTES, f);
    } finally {
        FileUtils.deleteQuietly(f);
    }
}