Example usage for java.io Writer toString

List of usage examples for java.io Writer toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:net.sf.zekr.engine.template.TemplateEngine.java

/**
 * @param name the file name of the desired template
 * @return the result <code>String</code> after the context map is merged (applied) into the source
 *         template file./*ww w. ja v  a 2  s .  co m*/
 * @throws Exception
 */
public String getUpdated(String name) throws Exception {
    template = Velocity.getTemplate(name);
    Writer writer = new StringWriter();
    template.merge(context, writer);
    return writer.toString();
}

From source file:com.whatsthatlight.teamcity.hipchat.test.HipChatConfigurationControllerTest.java

private static String renderTemplate(Template template) throws TemplateException, IOException {
    HashMap<String, Object> templateMap = new HashMap<String, Object>();
    Writer writer = new StringWriter();
    template.process(templateMap, writer);
    writer.flush();/* w  ww  . j  ava 2s  . co  m*/
    String renderedTemplate = writer.toString();
    writer.close();
    return renderedTemplate;
}

From source file:org.springframework.hateoas.VndErrorsMarshallingTests.java

@Test
public void jaxbMarshalling() throws Exception {

    Writer writer = new StringWriter();
    marshaller.marshal(errors, writer);/*  w  ww. j a v  a  2s  . c  o  m*/
    assertThat(writer.toString(), is(xmlReference));
}

From source file:it.evilsocket.dsploit.core.System.java

public static synchronized void errorLogging(String tag, Exception e) {
    String message = "Unknown error.", trace = "Unknown trace.",
            filename = (new File(Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME))
                    .getAbsolutePath();/*w ww  .j a v  a 2s .c om*/

    if (e != null) {
        if (e.getMessage() != null && e.getMessage().isEmpty() == false)
            message = e.getMessage();

        else if (e.toString() != null)
            message = e.toString();

        Writer sWriter = new StringWriter();
        PrintWriter pWriter = new PrintWriter(sWriter);

        e.printStackTrace(pWriter);

        trace = sWriter.toString();

        if (mContext != null && getSettings().getBoolean("PREF_DEBUG_ERROR_LOGGING", false) == true) {
            try {
                FileWriter fWriter = new FileWriter(filename, true);
                BufferedWriter bWriter = new BufferedWriter(fWriter);

                bWriter.write(trace);

                bWriter.close();
            } catch (IOException ioe) {
                Log.e(TAG, ioe.toString());
            }
        }
    }

    setLastError(message);
    Log.e(tag, message);
    Log.e(tag, trace);
}

From source file:com.hp.autonomy.iod.client.api.search.FieldNamesTest.java

@Test
public void testGetJson() throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    final Writer output = new StringWriter();
    mapper.writeValue(output, fieldNames);
    final String json = output.toString();

    assertThat(json, is(/*from  ww  w .  j  av  a2  s .  co  m*/
            "{\"zero\":[{\"value\":\"1\",\"count\":1},{\"value\":\"2\",\"count\":2}],\"one\":[{\"value\":\"3\",\"count\":3},{\"value\":\"4\",\"count\":4},{\"value\":\"5\",\"count\":5}]}"));
}

From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XMLUtils.java

/**
 * Converts a Document to a String.//from  w w  w  . ja v  a 2  s  . c  o  m
 * 
 * @param document
 *          the Document to convert
 * @return a String
 * @throws XmlException
 *           if any error occurs
 */
public static String documentToString(Document document) throws XmlException {
    if (document == null) {
        return null;
    }
    try {
        final Transformer transformer = s_transformerFactory.newTransformer();
        final Source source = new DOMSource(document);
        final Writer writer = new StringWriter();
        final Result result = new StreamResult(writer);
        transformer.transform(source, result);
        return writer.toString();
    } catch (final TransformerConfigurationException e) {
        throw new XmlException(e);
    } catch (final TransformerException e) {
        throw new XmlException(e);
    }
}

From source file:org.dita.dost.TestUtils.java

/**
 * Read XML file contents into a string.
 * //from   w w  w  . ja  v  a  2  s  .c om
 * @param file XML file to read
 * @param normalize normalize whitespace
 * @return contents of the file
 * @throws Exception if parsing the file failed
 */
public static String readXmlToString(final File file, final boolean normalize, final boolean clean)
        throws Exception {
    final Writer std = new CharArrayWriter();
    InputStream in = null;
    try {
        in = new BufferedInputStream(new FileInputStream(file));
        final Transformer t = TransformerFactory.newInstance().newTransformer();
        XMLReader p = XMLReaderFactory.createXMLReader();
        p.setEntityResolver(CatalogUtils.getCatalogResolver());
        if (normalize) {
            t.setOutputProperty(OutputKeys.INDENT, "yes");
            p = new NormalizingXMLFilterImpl(p);
        }
        if (clean) {
            p = new CleaningXMLFilterImpl(p);
        }
        t.transform(new SAXSource(p, new InputSource(in)), new StreamResult(std));
    } finally {
        if (in != null) {
            in.close();
        }
    }
    return std.toString();
}

From source file:org.chtijbug.drools.entity.DroolsFactObject.java

public DroolsFactObject(Object realObject, int version) throws IOException {
    this.realObject = realObject;
    this.version = version;
    ObjectMapper mapper = new ObjectMapper();
    Writer strWriter = new StringWriter();
    mapper.writeValue(strWriter, realObject);
    this.realObject_JSON = strWriter.toString();
}

From source file:org.libreplan.web.error.PageForErrorOnEvent.java

private String getStacktrace() {
    Throwable exception = (Throwable) Executions.getCurrent().getAttribute("javax.servlet.error.exception");
    if (exception != null) {
        Writer stacktrace = new StringWriter();
        exception.printStackTrace(new PrintWriter(stacktrace));

        return stacktrace.toString();
    }/*from   w  w w.  j a  v  a  2 s . c  o  m*/
    return "";
}

From source file:com.sap.core.odata.core.debug.DebugInfoBodyTest.java

private String appendJson(final ODataResponse response) throws IOException {
    Writer writer = new StringWriter();
    DebugInfoBody body = new DebugInfoBody(response);
    body.appendJson(new JsonStreamWriter(writer));
    return writer.toString();
}