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.greenpepper.server.license.LicenceGenerator.java

private static void buildEvaluation(Date experyDate) throws Exception {
    File file = File.createTempFile("evaluation", ".lic");
    License license = License.evaluation("Some peeps evaluating", _2006, experyDate);
    LicenseManager lm = new LicenseManager(getLicenseParam());
    lm.store(license, file);//from   ww w .  jav a  2  s.c  o  m
    if (deleteFiles)
        file.deleteOnExit();
    System.out.println("# Evaluation Expery: " + new FormatedDate(experyDate).getFormatedDate());
    System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file))));
    System.out.println("");
}

From source file:io.osv.LoggingIsolationTest.java

private File newTemporaryFile() throws IOException {
    File file = File.createTempFile("test", null);
    forceDeleteOnExit(file);/*from w  ww . j a  va  2  s.c  om*/
    return file;
}

From source file:org.sylvani.bot.util.HttpUtil.java

public File download(String url) throws IOException {
    HttpClient httpClient = null;/*from   ww  w  . j ava2  s . c o m*/
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = httpClient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        long len = entity.getContentLength();
        InputStream inputStream = entity.getContent();
        // How do I write it?
        File tmpFile = File.createTempFile(String.valueOf(url.hashCode()), "tmp");
        try (FileOutputStream oStream = new FileOutputStream(tmpFile)) {
            IOUtils.copy(inputStream, oStream);
        }
        return tmpFile;
    }
    return null;
}

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

@Test
public void testReadInt() throws IOException {
    File openFile = File.createTempFile("test", "txt");
    openFile.deleteOnExit();//from w ww. j av a2 s.c om
    FileOutputStream out = new FileOutputStream(openFile);
    FileLog flog = new FileLog(openFile);
    IOUtils.write("line1\n", out);
    out.flush();
    ByteLogInputStream lis = new DirectFileLogAccess(flog).getInputStream(null);
    // Log instanatiated before data is written
    assertEquals(-1, lis.read());
    flog = new FileLog(openFile);
    lis = new DirectFileLogAccess(flog).getInputStream(null);
    assertEquals('l', lis.read());
    assertEquals('i', lis.read());
    assertEquals('n', lis.read());
    assertEquals('e', lis.read());
    assertEquals('1', lis.read());
    assertEquals('\n', lis.read());
    assertEquals(-1, lis.read());

    // Write more, but lis doesn't see the new data due to size limitation
    IOUtils.write("l2\n", out);
    out.flush();
    assertEquals(-1, lis.read());
    lis.close();
}

From source file:edu.umn.msi.tropix.proteomics.test.InstrumentsTest.java

public void testInstruments(final boolean fromFile) throws IOException {
    Instruments instruments;//  www  .ja v  a  2s  .co  m
    if (fromFile) {
        final File tempFile = File.createTempFile("tpxtest", "");
        tempFile.deleteOnExit();
        final FileOutputStream stream = new FileOutputStream(tempFile);
        IOUtils.copy(getClass().getResourceAsStream("instruments.csv"), stream);
        instruments = new Instruments(tempFile.getAbsolutePath());
    } else {
        instruments = new Instruments(ProteomicsTests.getResourceAsStream("instruments.csv"));
    }
    assert instruments.ionUsed("Default", "1+ fragments") != null : "Null check 1";
    assert instruments.ionUsed("Default", "w or w' series ions") != null : "Null check 2";
    assert instruments.ionUsed("MALDI QIT TOF", "1+ fragments") != null : "Null check 3";
    assert instruments.ionUsed("MALDI QIT TOF", "w or w' series ions") != null : "Null check 4";
    assert instruments.ionUsed("ETD TRAP", "c series ions") != null : "Null check 5";
    assert instruments.ionUsed("Default", "c series ions") != null : "Null check 6";
    assert instruments.ionUsed("MALDI QUAD TOF", "c series ions") != null : "Null check 7";

    assert instruments.ionUsed("NOT AN INSTRUMENT", "NOT AN ION SERIES") == null;

    assert instruments.ionUsed("Default", "1+ fragments") : "Check 1";
    assert !instruments.ionUsed("Default", "w or w' series ions") : "Check 2";
    assert instruments.ionUsed("MALDI QIT TOF", "1+ fragments") : "Check 3";
    assert !instruments.ionUsed("MALDI QIT TOF", "w or w' series ions") : "Check 4";
    assert instruments.ionUsed("ETD TRAP", "c series ions") : "Check 5";
    assert !instruments.ionUsed("Default", "c series ions") : "Check 6";
    assert !instruments.ionUsed("MALDI QUAD TOF", "c series ions") : "Check 7";
}

From source file:org.sventon.web.ctrl.template.ExportControllerTest.java

@Test
public void testExport() throws Exception {
    final File tempFile = File.createTempFile("sventon-", "-test");
    tempFile.deleteOnExit();/*  w w w  .  ja  v  a  2 s .  c  o m*/

    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final UserRepositoryContext context = new UserRepositoryContext();
    final MultipleEntriesCommand command = new MultipleEntriesCommand();
    final PathRevision[] entriesToExport = new PathRevision[] {
            new PathRevision("/trunk/file1", Revision.create(100)),
            new PathRevision("/tags/test/file2", Revision.create(101)) };
    command.setName(new RepositoryName("test"));
    command.setEntries(entriesToExport);

    assertFalse(context.getIsWaitingForExport());
    assertNull(context.getExportUuid());

    final ExportController ctrl = new ExportController(new ExportExecutor() {
        public UUID submit(MultipleEntriesCommand command, SVNConnection connection, long pegRevision) {
            return UUID.fromString(UUID_STRING);
        }

        public void downloadByUUID(UUID uuid, HttpServletRequest request, HttpServletResponse response)
                throws IOException {
        }

        public void delete(UUID uuid) {
        }

        public int getProgress(UUID uuid) {
            return 1;
        }
    });

    final ModelAndView modelAndView = ctrl.svnHandle(null, command, 123, context, request, response, null);
    assertNotNull(modelAndView);

    assertTrue(context.getIsWaitingForExport());
    assertEquals(UUID_STRING, context.getExportUuid().toString());
}

From source file:io.spring.batch.DownloadingStepExecutionListener.java

@Override
public void beforeStep(StepExecution stepExecution) {
    String fileName = (String) stepExecution.getExecutionContext().get("fileName");

    Resource resource = this.resourceLoader.getResource(fileName);

    try {// ww  w .  j  av a2 s .c o  m
        File file = File.createTempFile("input", ".csv");

        StreamUtils.copy(resource.getInputStream(), new FileOutputStream(file));

        stepExecution.getExecutionContext().put("localFile", file.getAbsolutePath());
        System.out.println(">> downloaded file : " + file.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:azkaban.app.AzkabanApplicationTest.java

private File mktempdir(String name) throws IOException {
    File dir = File.createTempFile(name, ".d");
    FileUtils.forceDelete(dir);//w  w w  .j av a 2  s.  c  o m
    FileUtils.forceMkdir(dir);
    return dir;
}

From source file:edu.umn.msi.tropix.proteomics.test.ProteomicsInputTest.java

public void testProteomicsInput(final boolean readFromFile) throws Exception {
    BiomlWriter input = null;//from   w  w  w .  j a  va2 s.  c o m
    if (readFromFile) {
        final File tempFile = File.createTempFile("tpxtest", "");
        tempFile.deleteOnExit();
        FileUtils.writeStringToFile(tempFile,
                IOUtils.toString(getClass().getResourceAsStream("proteomicsInput1.xml")));
        input = new BiomlWriter(tempFile.getAbsolutePath());
    } else {
        input = new BiomlWriter(getClass().getResourceAsStream("proteomicsInput1.xml"));

    }
    boolean wasException = false;
    try {
        input.addVariable("test heading", "test");
    } catch (final IllegalArgumentException e) {
        wasException = true;
    }
    assert wasException;
    input.addHeader("test heading 2");
    input.addVariable("test heading 2", "param1", "param1 value again");
    input.addVariable("test heading 2", "param2", "param2 value");
    final String xml = input.toString();
    assert xml.contains("label=\"test heading 2\"") : "XML did not contain heading 2 label";
    assert xml.contains("label=\"test heading 2, param1\"") : "XML did not contain param1 input";
    assert xml.contains("label=\"test heading 2, param2\"") : "XML did not contain param2 input";
    assert xml.contains(">param1 value again<") : "XML did not contain param1 value";
    assert xml.contains(">param2 value<") : "XML did not contain param2 value";
    assert xml.contains("label=\"test heading, param1\"") : "XML did not contain old param1 value";
    assert xml.contains(">param1 value<") : "XML did not contain old param1 value";
}

From source file:net.netheos.pcsapi.BytesIOTest.java

@Before
public void setUp() throws Exception {
    tmpDir = File.createTempFile("pcs_api", ".dir");
    tmpDir.delete();//from w w w  .j av  a  2s. c om
    tmpDir.mkdirs();
}