List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:hudson.maven.settings.SettingsProviderUtils.java
/** * /*w ww.j a v a 2 s . co m*/ * @return a temp file which must be deleted after use */ public static File copyConfigContentToFile(Config config) throws IOException { File tmpContentFile = File.createTempFile("config", "tmp"); FileUtils.writeStringToFile(tmpContentFile, config.content); return tmpContentFile; }
From source file:net.ggtools.maven.DDLGeneratorIntegrationTest.java
@BeforeMethod public void setUp() throws Exception { ddlFile = File.createTempFile("DDLGeneratorIT", ".sql"); ddlFile.deleteOnExit();//from w ww . j a v a 2 s . c o m mojo.setDdlFile(ddlFile); mojo.setDialect(Oracle10gDialect.class.getName()); mojo.setDefaultSchema(SCHEMA); mojo.setNamingStrategy(ImprovedNamingStrategy.class.getName()); mojo.setPersistenceUnitName(MY_PU); mojo.setPersistenceXmlLocations(PERSISTENCE_XML_LOCATIONS); mojo.setUseNewGenerator(true); mojo.setLog(log); }
From source file:com.alibaba.otter.node.etl.common.io.compress.impl.AbstractCompressor.java
public InputStream compress(InputStream input) throws CompressException { FileOutputStream output = null; try {// ww w . j ava 2s. c om File temp = File.createTempFile("compress_", "jkt"); output = new FileOutputStream(temp); //?? compressTo(input, output); return new FileInputStream(temp); } catch (IOException e) { throw new CompressException("An I/O Exception has occured", e); } finally { IOUtils.closeQuietly(output); } }
From source file:coral.CoralHeadServable.java
@Override public void init(Properties properties, BlockingQueue<Message> loopQueue, Linker linker) { shell = (Shell) properties.get("shell"); if (!properties.containsKey("coral.head.res")) { try {// w ww .j a v a 2 s . c o m res = File.createTempFile("coral", "server"); res.delete(); res.mkdirs(); } catch (IOException e1) { throw new RuntimeException( "problem creating temporary directory for polyp, please specify with coral.polyp.res", e1); } } else { res = new File(properties.getProperty("coral.head.res"), "server_res/"); res.mkdirs(); } mainfilename = properties.getProperty("coral.head.main", "main.html"); String sidebarfilename = properties.getProperty("coral.head.sidebar", "servervm/sidebar.html"); File dir = new File(properties.getProperty("exp.basepath", "./")); File sidebarfile = new File(dir, sidebarfilename); String sidebartext = "<html><a href='" + CoralUtils.getHostStr() + CoralUtils.SERVER_KEY + "/info.vm'>SERVER</a></html>"; if (sidebarfile.exists()) { try { sidebartext = new Scanner(sidebarfile).useDelimiter("\\Z").next(); } catch (FileNotFoundException e) { logger.warn("Could not read sidebar file " + sidebarfilename, e); } } try { sidebrowser = new Browser(shell, SWT.NONE); } catch (SWTError e) { logger.warn("Could not instantiate sidebar Browser: ", e); throw new RuntimeException("Could not instantiate Browser", e); } super.setup(); browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); sidebrowser.setText(sidebartext); sidebrowser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); sidebrowser.addLocationListener(getLocationListener()); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 5; gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); // Shell shell = new Shell(SWT.NO_TRIM | SWT.ON_TOP); // shell.setLayout(new FillLayout()); // shell.setBounds(Display.getDefault().getPrimaryMonitor().getBounds()); // shell.setBounds(20,20,1044,788); // shell.open(); // res.mkdirs(); logger.debug("ready"); }
From source file:org.dkpro.lab.reporting.ChartUtilTest.java
@Test public void testSvg() throws Exception { double[][] data = new double[2][10]; for (int n = 1; n < 10; n++) { data[0][n] = 1.0 / n;/*w w w .j a v a 2 s . com*/ data[1][n] = 1.0 - (1.0 / n); } DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries("data", data); JFreeChart chart = ChartFactory.createXYLineChart(null, "Recall", "Precision", dataset, PlotOrientation.VERTICAL, false, false, false); chart.getXYPlot().setRenderer(new XYSplineRenderer()); chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0); chart.getXYPlot().getDomainAxis().setRange(0.0, 1.0); File tmp = File.createTempFile("testfile", ".svg"); try (OutputStream os = new FileOutputStream(tmp)) { ChartUtil.writeChartAsSVG(os, chart, 400, 400); } // String ref = FileUtils.readFileToString(new File("src/test/resources/chart/test.svg"), // "UTF-8"); // String actual = FileUtils.readFileToString(tmp, "UTF-8"); // assertEquals(ref, actual); }
From source file:org.openmrs.module.kenyaemr.page.controller.AdminSoftwareVersionPageController.java
public void controller(PageModel model, @RequestParam(value = "priorVersion", required = false) String priorVersion, HttpServletRequest request) {//from w w w . j a va 2 s .c o m model.addAttribute("priorVersion", null); model.addAttribute("log", null); if (request instanceof MultipartHttpServletRequest) { MultipartFile uploaded = ((MultipartHttpServletRequest) request).getFile("distributionZip"); if (uploaded != null) { // write this to a known file on disk, so we can use ZipFile, since ZipInputStream is buggy File file = null; try { file = File.createTempFile("distribution", ".zip"); file.deleteOnExit(); FileUtils.copyInputStreamToFile(uploaded.getInputStream(), file); List<String> log = Context.getService(ModuleDistroService.class).uploadDistro(file, request.getSession().getServletContext()); model.addAttribute("log", log); model.addAttribute("priorVersion", priorVersion); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); model.addAttribute("log", Arrays.asList("Error", ex.getMessage(), sw.toString())); } } } String currentVersion = ModuleFactory.getModuleById("kenyaemr").getVersion(); model.put("currentKenyaEmrVersion", currentVersion); }
From source file:ZipUtilInPlaceTest.java
public void testRemoveEntry() throws IOException { File src = new File(getClass().getResource("demo.zip").getPath()); File dest = File.createTempFile("temp", null); try {//from w w w . j a v a 2 s . c om FileUtils.copyFile(src, dest); assertTrue(ZipUtil.containsEntry(dest, "bar.txt")); ZipUtil.removeEntry(dest, "bar.txt"); assertTrue("Result zip misses entry 'foo.txt'", ZipUtil.containsEntry(dest, "foo.txt")); assertTrue("Result zip misses entry 'foo1.txt'", ZipUtil.containsEntry(dest, "foo1.txt")); assertTrue("Result zip misses entry 'foo2.txt'", ZipUtil.containsEntry(dest, "foo2.txt")); assertFalse("Result zip still contains 'bar.txt'", ZipUtil.containsEntry(dest, "bar.txt")); } finally { FileUtils.deleteQuietly(dest); } }
From source file:com.google.jenkins.plugins.credentials.oauth.P12ServiceAccountConfigTestUtil.java
private static File getTempFolder() throws IOException { if (tempFolder == null) { tempFolder = File.createTempFile("temp", Long.toString(System.nanoTime())); if (!tempFolder.delete()) { throw new IOException("Could not delete temp file: " + tempFolder.getAbsolutePath()); }// w w w . j av a 2s .c o m if (!tempFolder.mkdir()) { throw new IOException("Could not create temp directory: " + tempFolder.getAbsolutePath()); } tempFolder.deleteOnExit(); } return tempFolder; }
From source file:hudson.util.XStreamTest.java
/** * Tests that ConcurrentHashMap is serialized into a more compact format, * but still can deserialize to older, verbose format. *//*from w w w . j av a 2 s. c o m*/ public void testConcurrentHashMapSerialization() throws Exception { Foo foo = new Foo(); foo.m.put("abc", "def"); foo.m.put("ghi", "jkl"); File v = File.createTempFile("hashmap", "xml"); try { new XmlFile(v).write(foo); // should serialize like map String xml = FileUtils.readFileToString(v); assertFalse(xml.contains("java.util.concurrent")); //System.out.println(xml); Foo deserialized = (Foo) xstream.fromXML(xml); assertEquals(2, deserialized.m.size()); assertEquals("def", deserialized.m.get("abc")); assertEquals("jkl", deserialized.m.get("ghi")); } finally { v.delete(); } // should be able to read in old data just fine Foo map = (Foo) new XStream2().fromXML(getClass().getResourceAsStream("old-concurrentHashMap.xml")); assertEquals(1, map.m.size()); assertEquals("def", map.m.get("abc")); }
From source file:com.kylinolap.job.hadoop.cube.MergeCuboidJobTest.java
@Test public void test() throws Exception { // String input = // "src/test/resources/data/base_cuboid,src/test/resources/data/6d_cuboid"; String output = "target/test-output/merged_cuboid"; String cubeName = "test_kylin_cube_with_slr_ready"; String jobname = "merge_cuboid"; File baseFolder = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "base"); baseFolder.delete();//from w ww . ja v a 2 s.c om baseFolder.mkdir(); FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), baseFolder); baseFolder.deleteOnExit(); File sixDFolder = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "6d"); sixDFolder.delete(); sixDFolder.mkdir(); FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), sixDFolder); sixDFolder.deleteOnExit(); FileUtil.fullyDelete(new File(output)); // CubeManager cubeManager = // CubeManager.getInstanceFromEnv(this.getTestConfig()); String[] args = { "-input", baseFolder.getAbsolutePath() + "," + sixDFolder.getAbsolutePath(), "-cubename", cubeName, "-segmentname", "20130331080000_20131212080000", "-output", output, "-jobname", jobname }; assertEquals("Job failed", 0, ToolRunner.run(conf, new MergeCuboidJob(), args)); }