List of usage examples for java.io StringWriter toString
public String toString()
From source file:cc.kune.core.server.manager.file.FileDownloadManagerUtils.java
/** * Gets the inpu stream as string.//from ww w . j a v a 2s . c om * * @param iStream * the i stream * @return the inpu stream as string * @throws IOException * Signals that an I/O exception has occurred. */ public static String getInpuStreamAsString(final InputStream iStream) throws IOException { final StringWriter writer = new StringWriter(); IOUtils.copy(iStream, writer, "UTF-8"); return writer.toString(); }
From source file:Main.java
static String readFully(Reader reader) throws IOException { try {/*w ww . java2 s . co m*/ StringWriter writer = new StringWriter(); char[] buffer = new char[1024]; int count; while ((count = reader.read(buffer)) != -1) { writer.write(buffer, 0, count); } return writer.toString(); } finally { reader.close(); } }
From source file:com.betfair.testing.utils.cougar.assertions.AssertionUtils.java
private static String toString(Node k) throws IOException { ToTextStream s = new ToTextStream(); StringWriter sw = new StringWriter(); s.setWriter(sw);/*from www .j ava 2 s. com*/ s.serialize(k); return sw.toString(); }
From source file:hoot.services.utils.XmlDocumentBuilder.java
/** * Returns a string representation of an XML DOM * // w w w. ja va2 s . c o m * @param document an XML DOM * @return an XML string * @throws IOException */ public static String toString(Document document) throws IOException { StringWriter writer = new StringWriter(); write(document, writer); return writer.toString(); }
From source file:Main.java
public static String toString(XMLEvent event) { final StringWriter writer = new StringWriter(); try {/*from w w w . j a v a 2s . c om*/ event.writeAsEncodedUnicode(writer); } catch (XMLStreamException e) { writer.write(event.toString()); } return writer.toString(); }
From source file:Main.java
public static String returnDocAsString(Document doc) throws TransformerException { StringWriter sw = new StringWriter(); TransformerFactory tfFac = TransformerFactory.newInstance(); // use null trandformation Transformer tf = tfFac.newTransformer(); tf.transform(new DOMSource(doc), new StreamResult(sw)); return sw.toString(); }
From source file:Main.java
/** * DOM to string./* w ww. j a v a2 s . c o m*/ * * @param doc * the doc * @return the string */ /* * from: * http://www.journaldev.com/71/utility-java-class-to-format-xml-document * -to-xml-string-and-xml-to-document */ public static String DOMToString(Document doc) { String xmlString = ""; if (doc != null) { try { TransformerFactory transfac = TransformerFactory.newInstance(); Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(doc); trans.transform(source, result); xmlString = sw.toString(); } catch (Exception e) { e.printStackTrace(); } } return xmlString; }
From source file:com.topsem.common.mapper.JaxbMapper.java
/** * Java Object->Xml with encoding.//from w w w . j a v a 2 s .c o m */ public static String toXml(Object root, Class clazz, String encoding) { try { StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(root, writer); return writer.toString(); } catch (JAXBException e) { throw Throwables.propagate(e); } }
From source file:com.wsun.seap.common.mapper.JaxbMapper.java
/** * Java Object->Xml with encoding.//from ww w . j a v a2 s . co m */ public static String toXml(Object root, Class clazz, String encoding) { try { StringWriter writer = new StringWriter(); createMarshaller(clazz, encoding).marshal(root, writer); return writer.toString(); } catch (JAXBException e) { throw ExceptionUtil.unchecked(e); } }
From source file:Main.java
/** * Renders an XML node to a string// www . j av a2s. c o m * @param node The xml node to render * @return the rendered string or null if it failed conversion */ public static String renderNode(Node node) { if (node == null) return null; try { StringWriter writer = new StringWriter(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } catch (Throwable e) { return null; } }