List of usage examples for java.io ByteArrayOutputStream toString
public synchronized String toString()
From source file:net.bpelunit.framework.control.util.BPELUnitUtil.java
private static String serializeXML(Node node) throws TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty(OutputKeys.METHOD, "xml"); ByteArrayOutputStream bOS = new ByteArrayOutputStream(); t.transform(new DOMSource(node), new StreamResult(bOS)); return bOS.toString(); }
From source file:com.server.GCS.java
public static CloudObject find(String bucket, String key) { try {/*from w w w . ja va 2s. c o m*/ Storage.Objects.Get getObject = storage.objects().get(bucket, key); ByteArrayOutputStream out = new ByteArrayOutputStream(); getObject.executeMediaAndDownloadTo(out); String value = out.toString(); JSONObject obj; JSONParser p = new JSONParser(); obj = (JSONObject) p.parse(value); return new CloudObject(getObject.getObject(), obj); } catch (com.google.api.client.http.HttpResponseException e) { // Log.e(tag, "Exception: " + e.getMessage()); e.printStackTrace(); return null; } catch (Exception e) { // Log.e(tag, "Exception: " + e.printStackTrace()); e.printStackTrace(); return null; } }
From source file:org.nlp2rdf.webservice.NIFParameterWebserviceFactory.java
/** * Factory method/* w w w. jav a2 s.c om*/ * * @param httpServletRequest * @return */ public static NIFParameters getInstance(HttpServletRequest httpServletRequest, String defaultPrefix) throws ParameterException, IOException { //twice the size to split key value String[] args = new String[httpServletRequest.getParameterMap().size() * 2]; int x = 0; for (Object key : httpServletRequest.getParameterMap().keySet()) { String pname = (String) key; //transform key to CLI style pname = (pname.length() == 1) ? "-" + pname : "--" + pname; //collect CLI args args[x++] = pname; args[x++] = httpServletRequest.getParameter((String) key); } String line; String content = ""; try { BufferedReader reader = new BufferedReader(new InputStreamReader(httpServletRequest.getInputStream())); while ((line = reader.readLine()) != null) { if (line.startsWith("---") || line.startsWith("Content") || line.startsWith("html")) continue; content += line; } } catch (IOException e) { e.printStackTrace(); } if (args.length == 0 && !content.isEmpty()) { args = new String[4]; String[] params = content.split("&"); if (params.length > 0) { String[] i = params[0].split("="); String[] id = params[1].split("="); if (i.length > 0) { args[0] = "--" + i[0]; args[1] = URLDecoder.decode(i[1], "UTF-8"); } if (id.length > 0) { args[2] = "-" + id[0]; args[3] = URLDecoder.decode(id[1], "UTF-8"); } content = ""; } } // System.out.println(content); //parse CLI args OptionParser parser = ParameterParser.getParser(args, defaultPrefix); OptionSet options = ParameterParser.getOption(parser, args); // print help screen if (options.has("h")) { String addHelp = ""; ByteArrayOutputStream baos = new ByteArrayOutputStream(); parser.printHelpOn(baos); throw new ParameterException(baos.toString()); } // parse options with webservice setted to true return ParameterParserMS.parseOptions(options, true, content); }
From source file:Main.java
public static String exception2String(Exception e) { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); PrintWriter err = new PrintWriter(arrayOutputStream); e.printStackTrace(err);// w w w . ja va 2 s . c o m err.close(); try { arrayOutputStream.close(); } catch (IOException e1) { } return arrayOutputStream.toString(); }
From source file:Main.java
public static String uncompress(InputStream inputStream) throws IOException { if (inputStream == null) { return null; }//from ww w . j av a 2 s. com ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPInputStream gunzip = new GZIPInputStream(inputStream); byte[] buffer = new byte[256]; int n; while ((n = gunzip.read(buffer)) >= 0) { out.write(buffer, 0, n); } return out.toString(); }
From source file:Main.java
private static String getStringFromRaw(Context context, int id) { String str;/*from w w w .ja v a 2s. c o m*/ try { Resources r = context.getResources(); InputStream is = r.openRawResource(id); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = is.read(); while (i != -1) { baos.write(i); i = is.read(); } str = baos.toString(); is.close(); } catch (IOException e) { str = ""; } return str; }
From source file:Main.java
public static String toString(Node node) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//w w w . j av a2s.co m toText(node, baos); } catch (Exception e) { //logger.error(ExceptionUtil.toString(e)); throw new RuntimeException(e); //return null; } return baos.toString(); }
From source file:Main.java
public static String file2String(File file) { FileInputStream fis = null;//from w ww . ja v a2 s .co m ByteArrayOutputStream baos = null; try { fis = new FileInputStream(file); baos = new ByteArrayOutputStream(); int i; while ((i = fis.read()) != -1) { baos.write(i); } String str = baos.toString(); return str; } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fis != null) fis.close(); if (baos != null) baos.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:net.heroicefforts.viable.android.rep.it.Main.java
private static final String toString(Throwable t) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); t.printStackTrace(ps);/*from w w w.j a v a2s. c o m*/ ps.flush(); return baos.toString(); }
From source file:jp.co.conit.sss.sp.ex1.util.HttpUtil.java
/** * GET??????/* w w w . ja v a 2 s .c o m*/ * * @param url {@code null}??? * @return */ public static String get(String url) throws Exception { if (url == null) { throw new IllegalArgumentException("'url' must not be null."); } String result = null; DefaultHttpClient httpclient = new DefaultHttpClient(getHttpParam()); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpclient.execute(httpGet); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); response.getEntity().writeTo(byteArrayOutputStream); result = byteArrayOutputStream.toString(); } catch (ClientProtocolException e) { throw new Exception(); } catch (IllegalStateException e) { throw new Exception(); } catch (IOException e) { throw new Exception(); } return result; }