List of usage examples for java.io ByteArrayOutputStream toString
public synchronized String toString()
From source file:Main.java
/** * @param throwable/* w w w. j av a2s .c o m*/ * @return return the stack-trace */ public static String getStackTrace(Throwable throwable) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream pstream = new PrintStream(baos); String stack = null; throwable.printStackTrace(pstream); pstream.flush(); stack = baos.toString(); return stack; }
From source file:com.labs64.utils.swid.support.JAXBUtils.java
/** * Write XML entity to the string.//w w w .j a v a 2 s.c o m * * @param entity * XML entity * @throws IllegalArgumentException * @throws SwidException * @param <T> * JAXB entity */ public static <T> String writeObjectToString(final T entity) { ByteArrayOutputStream destination = new ByteArrayOutputStream(); writeObject(entity, destination, null); return destination.toString(); }
From source file:Configuration.ConfigHelper.java
public static String getUserHome() { String home = System.getProperty("user.home"); if (home == null || home.length() <= 0) { try {//from w ww. ja v a 2 s.c o m Process exec = Runtime.getRuntime().exec(new String[] { "bash", "-c", "echo $HOME" }); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(exec.getInputStream(), baos); exec.getInputStream().close(); home = baos.toString(); } catch (Exception e) { return null; } } return home; }
From source file:Main.java
public static String toHTML(String xml) throws TransformerException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamResult result = new StreamResult(baos); xmlToHTMLTransformer.transform(new StreamSource(new ByteArrayInputStream(xml.getBytes())), result); return baos.toString(); }
From source file:Main.java
public static String prettyFormatXml(final String xml, final int indent) { final ByteArrayOutputStream bos = new ByteArrayOutputStream((int) (xml.length() * 1.5)); try {/* w w w . j a va 2 s . c o m*/ prettyFormatXml(new ByteArrayInputStream(xml.getBytes("UTF-8")), bos, indent); return bos.toString(); } catch (final UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:Main.java
public static String readString(InputStream is) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = is.read(buffer)) > 0) { bos.write(buffer, 0, len);//from w w w. j a v a 2 s . com } bos.close(); return bos.toString(); }
From source file:MainServer.UploadServlet.java
public static String inputStream2String(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i;//from www . j a va2 s. c om while ((i = is.read()) != -1) { baos.write(i); } return baos.toString(); }
From source file:Main.java
public static String readString(byte[] message, int start) { int pos = start; final int len = message.length; ByteArrayOutputStream os = new ByteArrayOutputStream(); while (pos < len) { if (message[pos] == '\0') { ++pos;/*from w ww. j a v a 2s . com*/ break; } os.write(message[pos++]); } return os.toString(); }
From source file:ch.itemis.xdocker.lib.TestDockerClient.java
public static String stripAnsi(String str) { if (str == null) return ""; try {//from w w w .ja va 2 s .co m ByteArrayOutputStream baos = new ByteArrayOutputStream(); AnsiOutputStream aos = new AnsiOutputStream(baos); aos.write(str.getBytes()); aos.close(); return baos.toString(); } catch (IOException e) { return str; } }
From source file:Main.java
/** * Transforms a memory document with XML format into an string according an * XSL file, and stores it in a file//from w ww . j a v a2 s . c om * * @param doc * The document to read * @param xslFile * The name of the XSL file which allows transformate XML into * String according its style * * @return String value of a DOM * * @throws FileNotFoundException * java.io.FileNotFoundException * @throws TransformerException * javax.xml.transform.TransformerException */ public static String write_DOM_into_an_String(Document doc, String xslFile) throws FileNotFoundException, TransformerException { // An instance of a object transformer factory TransformerFactory tFactory = TransformerFactory.newInstance(); // Creates a transformer object associated to the XSL file Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile)); // Holds a tree with the information of a document in the form of a DOM // tree DOMSource sourceId = new DOMSource(doc); // Makes the transformation from the source in XML to the output in // stream according the transformer in XSL ByteArrayOutputStream bAOS = new ByteArrayOutputStream(); transformer.transform(sourceId, new StreamResult(bAOS)); // Returns the string value of the stream return bAOS.toString(); }