List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:com.tango.BucketSyncer.S32S3TestFile.java
public S32S3TestFile() throws Exception { file = File.createTempFile(getClass().getName(), ".tmp"); data = S32S3MirrorTest.random(TEST_FILE_SIZE + (RandomUtils.nextInt() % 1024)); @Cleanup/*from w ww .ja v a 2 s. co m*/ FileOutputStream out = new FileOutputStream(file); IOUtils.copy(new ByteArrayInputStream(data.getBytes()), out); file.deleteOnExit(); }
From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java
public void testTempClassLoader_getClass() throws Exception { File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile(); File jar = File.createTempFile("testTempClassLoader_getClass", ".jar"); jar.deleteOnExit();//from w ww . j a v a 2 s. co m FileUtils.copyFile(sourceJar, jar); try { ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar); Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl); assertNotNull(klass); } finally { jar.delete(); } }
From source file:put.semantic.fcanew.script.HandcraftedScript.java
private File copy(String resource) throws IOException { File f = File.createTempFile("fca", null); f.deleteOnExit();/*from w ww.j a va2s .c om*/ try (InputStream input = HandcraftedScript.class.getClassLoader().getResourceAsStream(resource); FileOutputStream output = new FileOutputStream(f)) { IOUtils.copy(input, output); } return f; }
From source file:fr.itinerennes.bundler.cli.GtfsFileOptionHandlerTest.java
@BeforeClass public static void prepare() throws IOException { directory = File.createTempFile("junit-", "-itr.tmp"); directory.delete();/*from w w w . ja v a 2s . c o m*/ directory.mkdir(); invalidFile = File.createTempFile("junit-", "-itr.tmp"); gtfsFile = File.createTempFile("junit-", "-itr.tmp.zip"); final InputStream gtfsIn = GtfsFileOptionHandlerTest.class.getResourceAsStream("gtfs.zip"); IOUtils.copy(gtfsIn, new FileOutputStream(gtfsFile)); }
From source file:com.wavemaker.commons.util.utils.ClassLoaderUtilsTest.java
@Test public void tempClassLoader_getClassTest() throws Exception { File sourceJar = new ClassPathResource("com/wavemaker/commons/foojar.jar").getFile(); File jar = File.createTempFile("tempClassLoader_getClassTest", ".jar"); jar.deleteOnExit();/*from w w w. j ava2 s.c o m*/ FileUtils.copyFile(sourceJar, jar); try { ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar); Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl); assertNotNull(klass); } finally { jar.delete(); } }
From source file:io.selendroid.builder.AndroidDriverAPKBuilder.java
public File extractAndroidDriverAPK() { InputStream is = AndroidDriverAPKBuilder.class.getResourceAsStream( PREBUILD_WEBVIEW_APP_PATH_PREFIX + SelendroidServerBuilder.getJarVersionNumber() + ".apk"); try {/*w w w . j a v a2 s . com*/ File tmpAndroidDriver = File.createTempFile("android-driver", ".apk"); IOUtils.copy(is, new FileOutputStream(tmpAndroidDriver)); IOUtils.closeQuietly(is); return tmpAndroidDriver; } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:brut.util.Jar.java
public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException { try {//ww w . ja va 2s .c o m InputStream in = Class.class.getResourceAsStream(resourcePath); if (in == null) { throw new FileNotFoundException(resourcePath); } File fileOut = File.createTempFile(tmpPrefix, null); fileOut.deleteOnExit(); OutputStream out = new FileOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); return fileOut; } catch (IOException ex) { throw new BrutException("Could not extract resource: " + resourcePath, ex); } }
From source file:com.seleniumtests.ut.util.TestFileUtility.java
@Test(groups = { "ut" }) public void testZipUnzipFile() throws IOException { File f1 = File.createTempFile("data", ".txt"); File f2 = File.createTempFile("data2", ".txt"); FileUtils.writeStringToFile(f1, "some data"); FileUtils.writeStringToFile(f2, "other data"); List<File> fileList = new ArrayList<>(); fileList.add(f1);// w ww . j a va 2s . c o m fileList.add(f2); File zip = FileUtility.createZipArchiveFromFiles(fileList); Assert.assertTrue(zip.exists()); File outputDir = FileUtility.unzipFile(zip); File outFile1 = Paths.get(outputDir.getAbsolutePath(), f1.getName()).toFile(); File outFile2 = Paths.get(outputDir.getAbsolutePath(), f2.getName()).toFile(); Assert.assertTrue(outFile1.exists()); Assert.assertTrue(outFile2.exists()); Assert.assertEquals(FileUtils.readFileToString(outFile1), "some data"); }
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. j av a 2 s. c om * @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:net.hillsdon.reviki.configuration.TestDataDirImpl.java
@Override protected void setUp() throws Exception { File baseDirFile = File.createTempFile(getClass().getSimpleName(), "baseDir"); assertTrue(baseDirFile.delete());/* w ww . j av a 2 s . c o m*/ _baseDir = baseDirFile.getCanonicalPath(); _servletContext = EasyMock.createMock(ServletContext.class); _dataDir = new DataDirImpl(_servletContext, _baseDir); }