List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:edu.harvard.med.screensaver.io.workbook2.Workbook2UtilsTest.java
/** Requires manual inspection to verify success */ public void testImageExport() throws Exception { try {//w w w. j a v a2s . com File file = File.createTempFile("testImageExport", ".xls"); OutputStream out = new FileOutputStream(file); WritableWorkbook workbook = Workbook.createWorkbook(out); WritableSheet sheet = workbook.createSheet("sheet1", 0); InputStream imageIn = Workbook2UtilsTest.class.getResourceAsStream("arrow-first.png"); byte[] imageData = IOUtils.toByteArray(imageIn); Workbook2Utils.writeCell(sheet, 1, 0, "image:"); Workbook2Utils.writeImage(sheet, 1, 1, imageData); workbook.write(); workbook.close(); log.warn("must manually verify that image was exported to workbook " + file); } catch (Exception e) { // prefer not to maintain this type of test, so allow the error to go to console -sde4 e.printStackTrace(); } }
From source file:com.intuit.tank.tools.debugger.PanelBuilder.java
public static File createWorkingDir(AgentDebuggerFrame frame, String baseUrl) { try {/*from w w w . j a v a2 s. c o m*/ File temp = File.createTempFile("temp", Long.toString(System.nanoTime())); temp.delete(); temp = new File(temp.getAbsolutePath() + ".d"); temp.mkdir(); workingDir = temp; // create settings.xml writeSettings(workingDir, getHeaders(baseUrl)); System.setProperty("WATS_PROPERTIES", workingDir.getAbsolutePath()); } catch (IOException e) { LOG.error("Error creating temp working dir: " + e); frame.showError("Error creating temp working dir: " + e); } return workingDir; }
From source file:net.grinder.util.LogCompressUtilTest.java
@Test public void testLogCompressDecompress() throws IOException { File file = new File(LogCompressUtilTest.class.getResource("/grinder1.properties").getFile()); byte[] zippedContent = LogCompressUtils.compress(file); File createTempFile2 = File.createTempFile("a22aa", ".zip"); createTempFile2.deleteOnExit();// ww w. ja v a 2s. com FileUtils.writeByteArrayToFile(createTempFile2, zippedContent); File createTempFile = File.createTempFile("a22", "tmp"); LogCompressUtils.decompress(zippedContent, createTempFile); assertThat(createTempFile.exists(), is(true)); byte[] unzippedContent = FileUtils.readFileToByteArray(createTempFile); assertThat(unzippedContent, is(FileUtils.readFileToByteArray(file))); }
From source file:gamepub.cloud.cloudUpload.java
public File stream2file(InputStream in) throws IOException { final File tempFile = File.createTempFile("stream2file", ".tmp"); tempFile.deleteOnExit();/*from w w w . j a v a 2 s . com*/ FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copy(in, out); return tempFile; }
From source file:com.machinelinking.cli.exporterTest.java
@Test public void testRun() throws IOException { final File in = new File("src/test/resources/dumps/enwiki-latest-pages-articles-p1.xml.gz"); final File out = File.createTempFile("csv-exporter", ".csv"); final int exitCode = new exporter() .run(String.format("--prefix http://en.wikipedia.org --in %s --out %s --threads 1", in.getAbsolutePath(), out.getAbsolutePath()).split(" ")); Assert.assertEquals(exitCode, 0);//from ww w .j av a2 s . c om Assert.assertEquals(FileUtils.readLines(out).size(), 11761); }
From source file:io.fabric8.maven.rt.ReadYaml.java
public BoosterYaml readYaml(String boosterUrl) throws IOException { //Lets convert the string boosterUrl to URl format. URL url = new URL(boosterUrl); //Create a temp file to read the data from URL File file = File.createTempFile("booster", ".yaml"); //Read the data from URl and copy it to File FileUtils.copyURLToFile(url, file);/*from ww w . j ava 2s . c om*/ //Lets convert the file Bosster Yaml object and return BoosterYaml Object final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(file, BoosterYaml.class); }
From source file:org.openmrs.module.dataexchange.DataExchangeComponentTest.java
@Test public void shouldExportAndImportConceptsWithRelatedMetadata() throws Exception { File conceptsFile = null;/*w w w .ja v a2 s. c o m*/ try { conceptsFile = File.createTempFile("concepts", ".xml"); dataExporter.exportConcepts(conceptsFile.getPath(), new HashSet<Integer>(Arrays.asList(23, 5089))); dataImporter.importData(conceptsFile.getPath()); } finally { if (conceptsFile != null) { conceptsFile.delete(); } } }
From source file:com.tc.websocket.queue.TempFileMonitor.java
public void run() { if (TaskRunner.getInstance().isClosing()) { return;//from w w w . j a v a 2s .c o m } try { File temp = File.createTempFile("temp", "temp"); String absolutePath = temp.getAbsolutePath(); String tempFilePath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator)); System.out.println("cleaning out directory " + tempFilePath); File tempdir = new File(tempFilePath); File[] files = tempdir.listFiles(); temp.delete();//cleanup for (File file : files) { String name = file.getName(); if (file.exists() && name.startsWith("eo") && name.endsWith("tm")) { //calculate the age Date lastmod = new Date(file.lastModified()); long minutes = DateUtils.getTimeDiffMin(lastmod, new Date()); if (minutes >= 5) { FileUtils.deleteQuietly(file); } } } } catch (Exception e) { logger.log(Level.SEVERE, null, e); } }
From source file:cz.cuni.amis.planning4j.sicstus.AbstractSicstusPlanner.java
private static File createTempFileFromStream(InputStream s) { try {//from w w w.ja v a 2 s. c o m File tempFile = File.createTempFile("Sicstus", ".sav"); FileOutputStream output = new FileOutputStream(tempFile); IOUtils.copy(s, output); output.close(); return tempFile; } catch (IOException ex) { throw new PlanningException("Error preparing save file"); } }
From source file:com.wavemaker.commons.util.utils.ConversionUtilsTest.java
@Test public void convertToResourceListTest() throws Exception { List<File> fileList = new ArrayList<>(); File file1 = File.createTempFile("file1", ".txt"); File file2 = File.createTempFile("file2", ".txt"); File file3 = Files.createTempDirectory("file3").toFile(); try {//from w w w . j a va 2 s . c o m fileList.add(file1); fileList.add(file2); fileList.add(file3); List<Resource> resources = ConversionUtils.convertToResourceList(fileList); assertEquals(resources.size(), fileList.size()); assertEquals(resources.get(0).getFilename(), file1.getName()); assertEquals(resources.get(1).getFilename(), file2.getName()); assertEquals(resources.get(2).getFilename(), file3.getName()); } finally { file1.delete(); file2.delete(); file3.delete(); } }