Example usage for java.io StringWriter toString

List of usage examples for java.io StringWriter toString

Introduction

In this page you can find the example usage for java.io StringWriter toString.

Prototype

public String toString() 

Source Link

Document

Return the buffer's current value as a string.

Usage

From source file:Main.java

private static String getXmlString(Document document, String tagName)
        throws ParserConfigurationException, SAXException, IOException, TransformerException {
    NodeList nodeList = document.getElementsByTagName(tagName);
    if (nodeList.getLength() < 1) {
        throw new IllegalArgumentException("no " + tagName + " found");
    }/*from w  ww . j  a va 2s  .  c o m*/
    Node sub = nodeList.item(0);
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document subdoc = db.newDocument();
    subdoc.appendChild(sub.cloneNode(true));

    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer();
    DOMSource domSource = new DOMSource(subdoc);
    StringWriter sw = new StringWriter();
    StreamResult xmlResult = new StreamResult(sw);
    transformer.transform(domSource, xmlResult);
    sw.flush();
    return sw.toString();
}

From source file:com.mymita.vaadlets.demo.AddonDemoApplication.java

private static VerticalLayout createStackTraceLabel(final Exception e) {
    final VerticalLayout vl = new VerticalLayout();
    vl.setMargin(true);/* www  . j  ava2 s . co m*/
    vl.addComponent(new Label("<h1>Error</h1>", Label.CONTENT_XHTML));
    final StringWriter buf = new StringWriter();
    e.printStackTrace(new PrintWriter(buf));
    vl.addComponent(new Label(buf.toString(), Label.CONTENT_PREFORMATTED));
    return vl;
}

From source file:com.jsonstore.jackson.JsonOrgModule.java

public static String serialize(JSONObject obj) {
    try {/*from w w w. j  ava2s.co m*/
        StringWriter writer = new StringWriter();

        JsonOrgModule.mapper.writeValue(writer, obj);

        writer.close();

        return writer.toString();
    }

    catch (Throwable e) {
        return null;
    }
}

From source file:com.github.triceo.robozonky.notifications.email.AbstractEmailingListener.java

protected static String stackTraceToString(final Throwable t) {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);//ww w  . j ava 2 s  .com
    return sw.toString();
}

From source file:com.jsonstore.jackson.JsonOrgModule.java

public static String serialize(JSONArray array) {
    try {/*from  w  w  w .  ja va  2s  .  c o  m*/
        StringWriter writer = new StringWriter();

        JsonOrgModule.mapper.writeValue(writer, array);

        writer.close();

        return writer.toString();
    }

    catch (Throwable e) {
        return null;
    }
}

From source file:org.apache.taverna.activities.interaction.InteractionUtils.java

public static String objectToJson(final Object o) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    final StringWriter sw = new StringWriter();
    mapper.writeValue(sw, o);//from  www . j  a v  a  2s.  c  o m
    final String theString = sw.toString();
    return theString;
}

From source file:Main.java

public static String transform2String(Node node) throws TransformerException {
    final TransformerFactory transFactory = TransformerFactory.newInstance();
    final Transformer transformer = transFactory.newTransformer();
    final StringWriter buffer = new StringWriter();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.transform(new DOMSource(node), new StreamResult(buffer));
    return buffer.toString();
}

From source file:com.wdhis.util.JacksonUtil.java

public static String bean2Json(Object obj) throws IOException {
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createJsonGenerator(sw);
    mapper.writeValue(gen, obj);/*from   www . j av a 2 s. c o  m*/
    gen.close();
    return sw.toString();
}

From source file:ch.algotrader.esper.EsperTestBase.java

protected static Module load(final Reader in, final String name) throws IOException, ParseException {
    StringWriter buffer = new StringWriter();
    IOUtils.copy(in, buffer);// w  w  w  .  ja v  a 2 s. c om
    return EPLModuleUtil.parseInternal(buffer.toString(), name);
}

From source file:de.zib.gndms.GORFX.action.dms.SliceStageInORQCalculator.java

public static String loggalbeStringArray(String[] sl) {

    if (sl.length == 0)
        return "null";

    StringWriter sw = new StringWriter();
    for (String s : sl)
        sw.write(s);//from   ww  w .ja va  2 s.c o m

    return sw.toString();
}