List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:gamepub.cloud.cloudUpload.java
public File stream2file(InputStream in) throws IOException { final File tempFile = File.createTempFile("stream2file", ".tmp"); tempFile.deleteOnExit(); FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copy(in, out);//from www.j ava 2 s . c o m return tempFile; }
From source file:com.amazonaws.util.Md5UtilsTest.java
@Test public void testFile() throws Exception { File f = File.createTempFile("Md5UtilsTest-", "txt"); f.deleteOnExit(); FileUtils.writeStringToFile(f, "Testing MD5"); byte[] md5 = Md5Utils.computeMD5Hash(f); assertEquals("0b4f503b8eb7714ce12402406895cf68", StringUtils.lowerCase(Base16.encodeAsString(md5))); String b64 = Md5Utils.md5AsBase64(f); assertEquals("C09QO463cUzhJAJAaJXPaA==", b64); }
From source file:com.twitter.heron.common.config.SystemConfigTest.java
@Test public void testReadConfig() throws IOException { InputStream inputStream = getClass().getResourceAsStream(RESOURCE_LOC); if (inputStream == null) { throw new RuntimeException("Sample output file not found"); }//from w w w . j a v a2s .c o m File file = File.createTempFile("system_temp", "yaml"); file.deleteOnExit(); OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); outputStream.close(); SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(file.getAbsolutePath(), true).build(); Assert.assertEquals("log-files", systemConfig.getHeronLoggingDirectory()); Assert.assertEquals(ByteAmount.fromMegabytes(100), systemConfig.getHeronLoggingMaximumSize()); Assert.assertEquals(5, systemConfig.getHeronLoggingMaximumFiles()); Assert.assertEquals(Duration.ofSeconds(60), systemConfig.getHeronMetricsExportInterval()); }
From source file:de.nrw.hbz.regal.sync.ingest.DippMapping.java
private File createFile(String resourceName, String path) throws IOException { try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName)) { File tempFile = new File(path); tempFile.deleteOnExit(); try (FileOutputStream out = new FileOutputStream(tempFile)) { IOUtils.copy(in, out);/*from ww w .j a v a 2 s. c o m*/ return tempFile; } } }
From source file:com.hp.alm.ali.idea.rest.MyResultInfoTest.java
@Test public void testIndicatingOutputStream() throws IOException { File file = File.createTempFile("test", ""); file.deleteOnExit(); MyResultInfo info = new MyResultInfo(new IndicatingOutputStream(file, 6, new MockProgressIndicator())); ResultInfo result = ResultInfo.create(info.getOutputStream()); result.getBodyStream().write("foo".getBytes()); Assert.assertEquals("foo", info.getBodyAsString()); result.getBodyStream().write("bar".getBytes()); Assert.assertEquals("foobar", info.getBodyAsString()); }
From source file:com.helegris.szorengeteg.ui.MediaLoader.java
/** * Creates playable JavaFX audio from a byte array. To achieve this, it * creates and deletes a temporary file. * * @param audioBytes//from ww w . ja v a2 s. com * @return audio * @throws IOException */ public Media loadAudio(byte[] audioBytes) throws IOException { File tempFile = File.createTempFile("audio", null); tempFile.deleteOnExit(); IOUtils.write(audioBytes, new FileOutputStream(tempFile)); Media media = new Media(tempFile.toURI().toString()); return media; }
From source file:datavis.Gui.java
/** * Returns a new PSAWWB data list containing data pulled from TCOON's website * @param station The station number, e.g., 33 for Port Lavaca * @param interval The number of seconds between data samples, e.g., 86400 * @param start Date range start date/*from w ww. ja v a 2 s. com*/ * @param end Date range end date. Defaults to 1 year if null * @return A fresh DataList */ public static DataList_PWL_SURGE_ATP_WTP_WSD_BPR getDataFromServer(int station, int interval, Date start, Date end) throws UnsupportedEncodingException { String dateString = new String(), pattern = new String("%25Y%25j%2B%25H%25M"); DateFormat format = new SimpleDateFormat("MM.dd.yyyy"); File temp = null; URL url; if (interval % 360 != 0 || interval < 360) interval = 0; // default to monthly if (interval >= 86400) pattern = "%25m-%25d-%25Y"; if (start == null || end == null) dateString = "now,-1y"; else dateString = format.format(start) + "-" + format.format(end); try { temp = File.createTempFile("TCOON", null); temp.deleteOnExit(); url = new URL(String.format( "http://lighthouse.tamucc.edu/pd?stnlist=%03d&serlist=pwl,surge,atp,wtp,wsd,bpr&when=%s&whentz=UTC0&-action=csv&unit=metric&elev=stnd&interval=%s&datefmt=%s&rm=0&na=0", station, dateString, interval > 0 ? String.valueOf(interval) : "monthly", pattern)); Files.copy(url.openStream(), temp.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { } return new DataList_PWL_SURGE_ATP_WTP_WSD_BPR(temp.getAbsolutePath()); }
From source file:org.apache.camel.component.db4o.TestObjectContainerFactoryBean.java
public ObjectContainer getObject() throws Exception { File randomDatabase = File.createTempFile(getClass().getName(), "tmp"); randomDatabase.deleteOnExit(); objectContainer = Db4oEmbedded.openFile(randomDatabase.getAbsolutePath()); return objectContainer; }
From source file:$.MyMapping.java
private File createFile(String resourceName, String path) throws IOException { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName); File tempFile = new File(path); tempFile.deleteOnExit(); FileOutputStream out = null; try {//from w ww . jav a 2s . c om out = new FileOutputStream(tempFile); IOUtils.copy(in, out); } finally { if (out != null) out.close(); } return tempFile; }
From source file:de.nrw.hbz.regal.sync.ingest.OpusMapping.java
private File createFile(String resourceName, String path) throws IOException { try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName)) { File tempFile = new File(path); tempFile.deleteOnExit(); FileOutputStream out = null; try {/* www . j a va 2s . c om*/ out = new FileOutputStream(tempFile); IOUtils.copy(in, out); } finally { if (out != null) out.close(); } return tempFile; } }