List of usage examples for java.io StringWriter toString
public String toString()
From source file:function.Functions.java
protected static String toString(InputStream in) throws IOException { StringWriter out = new StringWriter(); copy(new InputStreamReader(in), out); out.close();//www .j a v a 2 s.c om in.close(); return out.toString(); }
From source file:com.twosigma.beaker.mimetype.MIMEContainer.java
protected static String exceptionToString(Exception e) { StringWriter w = new StringWriter(); PrintWriter printWriter = new PrintWriter(w); e.printStackTrace(printWriter);/* w w w .j a v a 2 s.c om*/ printWriter.flush(); return w.toString(); }
From source file:org.openmrs.module.sync.web.controller.EmailConfigController.java
/** * Utility method to return the json representation of an object *///ww w. ja v a 2 s . com private static String toJson(Object obj) { ObjectMapper mapper = new ObjectMapper(); StringWriter sw = new StringWriter(); try { mapper.writeValue(sw, obj); } catch (Exception e) { throw new APIException("Error converting to JSON", e); } return sw.toString(); }
From source file:org.eclipse.swordfish.core.util.xml.XmlUtil.java
public static String toString(Source source) { if (source == null) { return null; } else if (source instanceof StringSource) { return ((StringSource) source).getText(); } else {//from w w w . j a va 2 s . c o m StringWriter buffer = new StringWriter(); try { getTransformer().transform(source, new StreamResult(buffer)); } catch (TransformerException ex) { throw new RuntimeException(ex); } return buffer.toString(); } }
From source file:Main.java
public static String domToText(Document inDocument) throws TransformerException { StringWriter output = new StringWriter(); DOMSource source = new DOMSource(inDocument); StreamResult result = new StreamResult(output); transformer.transform(source, result); //this.getWatcher().setProgressText("saved " + getEditedFile().getAbsolutePath()); return output.toString(); }
From source file:Main.java
/** Returns the remainder of 'reader' as a string, closing it when done. */ public static String readFully(Reader reader) throws IOException { try {//from ww w .j av a 2 s. c o 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:Main.java
public static String docToString(Document doc) { try {/* w ww. j a v a 2 s.co m*/ DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); return writer.toString(); } catch (TransformerException ex) { throw new RuntimeException(ex); } }
From source file:org.cleverbus.common.Tools.java
/** * Marshals object graph into XML.//from w w w . j a va2 s . co m * * @param obj the object graph * @param sourceClass the input class * @return XML as string * @see XmlConverter */ public static String marshalToXml(Object obj, Class sourceClass) { Jaxb2Marshaller jaxb2 = new Jaxb2Marshaller(); jaxb2.setContextPath(sourceClass.getPackage().getName()); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); jaxb2.marshal(obj, result); return writer.toString(); }
From source file:Main.java
public static String toXmlString(Document doc) throws Exception { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); writer.flush();//from w w w .java2 s . co m return writer.toString(); }
From source file:org.vertx.java.http.eventbusbridge.util.SerializationHelper.java
private static String toXml(final Object xmlObject) throws JAXBException { StringWriter writer = new StringWriter(); Marshaller jaxbMarshaller = JAXB_CONTEXT.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(xmlObject, writer); return writer.toString(); }