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:com.jaspersoft.jasperserver.war.xmla.XMLUtils.java

/**
 * read a file from classpath into a string
 * @param uri the path to the file (e.g. com/jaspersoft/foo/bar.xsl)
 * @return the content of the file//  www  .  j ava  2 s . com
 * @throws IOException
 */
static String loadStyle(String uri) throws IOException {
    InputStream xslt = XMLUtils.class.getClassLoader().getResourceAsStream(uri);

    StringWriter xsltwriter = new StringWriter();
    IOUtils.copy(xslt, xsltwriter);

    return xsltwriter.toString();
}

From source file:com.tdclighthouse.prototype.utils.FreemarkerUtils.java

public static String renderTemplate(String templatePath, Map<String, Object> model, Class<?> classLoaderOfClass)
        throws TemplateException, IOException {
    if (StringUtils.isBlank(templatePath) || model == null) {
        throw new IllegalArgumentException("both templatePath and model are required.");
    }/* w  w w  .ja v  a 2 s .com*/
    Template tempalte = FreemarkerUtils.getTemplate(templatePath, classLoaderOfClass);
    StringWriter stringWriter = new StringWriter();
    tempalte.process(model, stringWriter);
    return stringWriter.toString();
}

From source file:org.uiautomation.ios.communication.Helper.java

public static JSONObject extractObject(HttpResponse resp) {
    String str = "";
    try {//from w ww  .  j  a v  a  2 s  .c o m
        InputStream is = resp.getEntity().getContent();
        StringWriter writer = new StringWriter();
        IOUtils.copy(is, writer, "UTF-8");

        str = writer.toString();
        return new JSONObject(str);
    } catch (Exception e) {
        throw new WebDriverException(str, e);
    }
}

From source file:org.uiautomation.ios.communication.Helper.java

public static String extractString(HttpResponse resp) {
    String str = "";
    try {//from w  w w .ja va  2 s.c om
        InputStream is = resp.getEntity().getContent();
        StringWriter writer = new StringWriter();
        IOUtils.copy(is, writer, "UTF-8");

        str = writer.toString();
        return str;
    } catch (Exception e) {
        throw new WebDriverException(str, e);
    }
}

From source file:Main.java

public static String nodeToString(Node noh) throws TransformerException {
    Transformer t = TransformerFactory.newInstance().newTransformer();
    StringWriter wr = new StringWriter();
    StreamResult result = new StreamResult(wr);

    t.transform(new DOMSource(noh), result);
    return wr.toString();
}

From source file:org.jenkinsci.plugins.jacksondatabind.JSONReadWrite.java

public static String toString(Object object) throws IOException {
    StringWriter stringWriter = new StringWriter();
    jsonMapper.writeValue(stringWriter, object);
    return stringWriter.toString();
}

From source file:Main.java

public static String convertToXml(Object obj, String encoding) {
    String result = null;/*  w  w  w .  java2s .c o m*/
    try {
        JAXBContext context = JAXBContext.newInstance(obj.getClass());
        Marshaller marshaller = context.createMarshaller();
        //         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
        //         marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, true);

        StringWriter writer = new StringWriter();
        marshaller.marshal(obj, writer);
        result = writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

From source file:com.jaspersoft.jasperserver.remote.ServicesUtils.java

/**
 * Convenient method to convert a REST obejct (like OperationResult) in an XML string.
 * Not suggested for big objects.// w  w w  .  ja  va2  s  .c o m
 * @param obj
 * @return
 */
public static String marshall(Object obj) {
    StringWriter sw = new StringWriter();
    Marshaller.marshal(obj, sw);
    return sw.toString();
}

From source file:com.scorpio4.util.io.StreamCopy.java

public static String toString(InputStream inputStream, String encoding) throws IOException {
    StringWriter writer = new StringWriter();
    IOUtils.copy(inputStream, writer, encoding);
    return writer.toString();
}

From source file:Main.java

public static String transformToString(Document doc) throws TransformerException {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    transformer.transform(source, result);
    return writer.toString();
}