List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:ca.weblite.xmlvm.XmlvmHelper.java
public static void runXmlvm(Project project, String[] args, File xmlvmJar) { try {//from w w w . ja va 2 s . co m //System.out.println(getProject().getProperties()); //System.out.println(this.getClassPath()); //System.out.println(System.getProperties()); Java j = (Java) project.createTask("java"); j.setMaxmemory("2G"); j.setJar(xmlvmJar); //j.setFailonerror(true); File log = File.createTempFile("foo", "bar"); j.setOutput(log); j.setFork(true); for (String arg : args) { Commandline.Argument a = j.createArg(); a.setValue(arg); } System.out.println("About to execute XMLVM..."); for (int i = 0; i < args.length; i++) { System.out.println("ARG: " + args[i]); } j.execute(); System.out.println(FileUtils.readFileToString(log)); System.out.println("Finished execution of XMLVM"); } catch (IOException ex) { Logger.getLogger(XMLVM.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fr.itinerennes.bundler.cli.GtfsUtilsTest.java
@BeforeClass public static void prepare() throws IOException { directory = File.createTempFile("junit-", "-itr.tmp"); directory.delete();// w w w . j av a 2 s .co m directory.mkdir(); invalidFile = File.createTempFile("junit-", "-itr.tmp"); gtfsFile = File.createTempFile("junit-", "-itr.tmp.zip"); final InputStream gtfsIn = GtfsUtilsTest.class.getResourceAsStream("gtfs.zip"); IOUtils.copy(gtfsIn, new FileOutputStream(gtfsFile)); }
From source file:be.i8c.sag.util.FileUtils.java
/** * Receives the fop.xconf stream and puts it in a temporary file. * * @param stream The stream tat will be written to the temporary file * @return Returns temporary file with the content of the stream * @throws IOException when the file couldn't be created *///from w w w . j a v a 2 s. c om public static File createTempFopConf(InputStream stream) throws IOException { File temp; temp = File.createTempFile("fop", ".xconf"); temp.deleteOnExit(); FileOutputStream out = new FileOutputStream(temp); IOUtils.copy(stream, out); return temp; }
From source file:Main.java
public static File UpdateZipFromPath(String sZipFile, String sPath) throws Exception { File tmpFile = File.createTempFile("z4zip-tmp-", ".zip"); tmpFile.deleteOnExit();//from ww w .ja v a 2 s.c om ZipFile inZip = new ZipFile(sZipFile); ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(tmpFile.getPath())); Enumeration<? extends ZipEntry> entries = inZip.entries(); while (entries.hasMoreElements()) { ZipEntry e = entries.nextElement(); outZip.putNextEntry(e); if (!e.isDirectory()) { File f = new File(sPath + "/" + e.getName()); if (f.exists()) { copy(new FileInputStream(f.getPath()), outZip); } else { copy(inZip.getInputStream(e), outZip); } } outZip.closeEntry(); } inZip.close(); outZip.close(); return tmpFile; }
From source file:com.msd.gin.halyard.tools.HalyardUpdateTest.java
@BeforeClass public static void setup() throws Exception { File rf = File.createTempFile("HalyardUpdateTest", ""); rf.delete();// w w w .ja v a2 s .c om rf.mkdirs(); ROOT = rf.toURI().toURL().toString(); if (!ROOT.endsWith("/")) { ROOT = ROOT + "/"; } ValueFactory vf = SimpleValueFactory.getInstance(); HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), TABLE, true, 0, true, 0, null); sail.initialize(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { sail.addStatement(vf.createIRI("http://whatever/subj" + i), vf.createIRI("http://whatever/pred"), vf.createIRI("http://whatever/obj" + j)); } } sail.commit(); sail.shutDown(); HalyardUpdate.conf = HBaseServerTestInstance.getInstanceConfig(); }
From source file:com.redhat.victims.mock.MockEnvironment.java
public static void initCache() throws IOException { TEMP_CACHE = File.createTempFile(CACHE_PREFIX, ""); FileUtils.forceDelete(TEMP_CACHE);// ww w .j a va2s .c om }
From source file:com.google.dart.tools.designer.model.HtmlRenderHelper.java
/** * @return the image of given HTML content, may be <code>null</code>. *///from w ww. j a v a 2 s . c o m public static Image renderImage(final String content) { try { File tempFile = File.createTempFile("htmlRender", ".html"); try { IOUtils2.writeBytes(tempFile, content.getBytes()); // start DumpRenderTree if (processOutputStream == null) { String path; { Bundle bundle = DartDesignerPlugin.getDefault().getBundle(); URL url = bundle.getEntry("lib/DumpRenderTree.app/Contents/MacOS/DumpRenderTree"); path = FileLocator.toFileURL(url).getPath(); } // ProcessBuilder builder = new ProcessBuilder(path, "-p", tempFile.getAbsolutePath()); ProcessBuilder builder = new ProcessBuilder(path, "-p", "-"); builder.redirectErrorStream(true); Process process = builder.start(); processOutputStream = process.getOutputStream(); processInputStream = process.getInputStream(); processReader = new BufferedReader(new InputStreamReader(processInputStream)); } long start = System.nanoTime(); // XXX // processOutputStream.write((tempFile.getAbsolutePath() + "\n").getBytes()); processOutputStream .write(("http://127.0.0.1:3030/Users/scheglov/dart/dwc_first/web/out/dwc_first.html\n") .getBytes()); processOutputStream.flush(); // read tree while (true) { String line = processReader.readLine(); System.out.println(line); if (line.isEmpty()) { break; } } // read image { processReader.readLine(); // ActualHash: processReader.readLine(); // Content-Type: image/png String lengthLine = processReader.readLine(); // Content-Length: 5546 int pngLength = Integer.parseInt(StringUtils.removeStart(lengthLine, "Content-Length: ")); // System.out.println("pngLength: " + pngLength); char[] pngChars = new char[pngLength]; readFully(processReader, pngChars); byte[] pngBytes = new String(pngChars).getBytes(); Image image = new Image(null, new ByteArrayInputStream(pngBytes)); System.out.println("imageTime: " + (System.nanoTime() - start) / 1000000.0); return image; } // // { // SessionInputBuffer buffer = new AbstractSessionInputBuffer() { // { // init(processInputStream, 1024, new BasicHttpParams()); // } // // @Override // public boolean isDataAvailable(int timeout) throws IOException { // return false; // } // }; // LineParser lineParser = new BasicLineParser(new ProtocolVersion("HTTP", 1, 1)); // HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser( // buffer, // lineParser, // new DefaultHttpResponseFactory(), // new BasicHttpParams()); // HttpResponse response = parser.parse(); // System.out.println(response); // HttpParams params = new BasicHttpParams(); // SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params); // HttpMessageParser<BasicHttpResponse> parser = new DefaultResponseParser( // inbuffer, // BasicLineParser.DEFAULT, // new DefaultHttpResponseFactory(), // params); // // HttpResponse response = parser.parse(); // } // while (true) { // String line = processReader.readLine(); // System.out.println(line); // } // // byte[] bytes = IOUtils2.readBytes(processInputStream); // int exitValue = process.exitValue(); // System.out.println("bytes: " + bytes.length); // System.out.println("bytesTime: " + (System.nanoTime() - start) / 1000000.0); // String output = new String(bytes); // System.out.println(StringUtils.substring(output, -10, 0)); //// System.out.println(output); // // // int pngOffset = output.indexOf("Content-Type: image/png"); // pngOffset = output.indexOf('\n', pngOffset) + 1; // pngOffset = output.indexOf('\n', pngOffset) + 1; // Image image = new Image(null, new ByteArrayInputStream(bytes, pngOffset, bytes.length // - pngOffset)); // System.out.println("imageTime: " + (System.nanoTime() - start) / 1000000.0); // return image; } finally { tempFile.delete(); } } catch (Throwable e) { e.printStackTrace(); } return null; }
From source file:io.github.blindio.prospero.core.browserdrivers.phantomjs.PhantomJSInstaller.java
static void installPhantomJS() { File tempArchive = null;//from w w w . java2 s . c o m try { tempArchive = File.createTempFile(PHANTOMJS_FILE_PREFIX, ArchiveFormat.getFileExtention()); FileUtils.copyURLToFile(new URL(PhantomJSArchiveFile.getDownloadURL()), tempArchive); tempArchive.deleteOnExit(); UnArchiver unarchiver = ArchiveFormat.getUnArchiver(); unarchiver.setSourceFile(tempArchive); File destDir = new File(getPhantomJSInstallDirPath()); if (!destDir.exists()) { destDir.mkdir(); } unarchiver.setDestDirectory(destDir); unarchiver.extract(); } catch (Exception e) { throw new ProsperoRuntimeAutomationException(e); } }
From source file:com.android.sdklib.repository.local.LocalPlatformPkgInfoTest.java
@NonNull private static File getJsonFile(String content) throws IOException { File json = File.createTempFile("testGetLibsFromJson", ""); json.deleteOnExit();/* www .java 2 s.co m*/ Files.write(content, json, Charsets.UTF_8); return json; }
From source file:com.fun.util.TesseractUtil.java
/** * // w w w . ja v a 2 s . co m * * @param imageFile * @param enlargeTimes * @param isEnlarge * @return * @throws IOException */ public static String recognize(File imageFile, int enlargeTimes, boolean isEnlarge) throws IOException { // 3??? File tmpScaledImage = File.createTempFile("tesseract-ocr-scaled", null); tmpScaledImage.deleteOnExit(); if (isEnlarge) scaled(imageFile, enlargeTimes, tmpScaledImage); // File tmpOutputBase = new File(tmpScaledImage.getAbsolutePath() + ".out"); File tmpOutputText = new File(tmpScaledImage.getAbsolutePath() + ".out.txt"); try { int exitCode = Runtime.getRuntime().exec(new String[] { "tesseract", // command tmpScaledImage.getAbsolutePath(), // imagename tmpOutputBase.getAbsolutePath(), // outputbase "-psm", "8", // pagesegmode, treat the image as a single word }).waitFor(); tmpScaledImage.delete(); // } catch (Exception e) { e.printStackTrace(); } // ? String text = Files.readFirstLine(tmpOutputText, Charsets.UTF_8); tmpOutputText.delete(); // if (StringUtils.isNotBlank(text)) { return text.trim().replaceAll("\\s|,", ""); } tmpOutputBase.delete(); return StringUtils.EMPTY; }