Example usage for java.io StringWriter getBuffer

List of usage examples for java.io StringWriter getBuffer

Introduction

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

Prototype

public StringBuffer getBuffer() 

Source Link

Document

Return the string buffer itself.

Usage

From source file:org.apache.syncope.core.logic.init.CamelRouteLoader.java

private String nodeToString(final Node content, final TransformerFactory tf) {
    String output = StringUtils.EMPTY;

    try {/*from   www  .j  a  v a2 s .  co m*/
        Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        StringWriter writer = new StringWriter();
        transformer.transform(new DOMSource(content), new StreamResult(writer));
        output = writer.getBuffer().toString();
    } catch (TransformerException e) {
        LOG.debug("While serializing route node", e);
    }

    return output;
}

From source file:org.hexlogic.model.DockerNodeService.java

public void createNode(String displayName, String hostName, int hostPort, String dockerApiVersion) {
    log.debug("Running createNode()...");
    try {/*from   ww  w.j  av a 2 s. c  om*/
        // serialize a host to a collection of key value pairs
        // UUID of our object is used as UUID of the configuration element.
        // Generate some random UUID. If another vCO object with this UUID exists, vCO action will fail. so this is considered safe.
        IEndpointConfiguration config = service.newEndpointConfiguration(UUID.randomUUID().toString());
        config.setString(DockerNode.DISPLAYNAME, displayName);
        config.setString(DockerNode.HOSTNAME, hostName);

        if (hostPort > 0 && hostPort < 65535) {
            config.setInt(DockerNode.HOSTPORT, hostPort);
        } else {
            config.setInt(DockerNode.HOSTPORT, DockerNode.defaultPort);
        }

        if (dockerApiVersion != null && !dockerApiVersion.isEmpty()) {
            config.setString(DockerNode.APIVERSION, dockerApiVersion);
        } else {
            config.setString(DockerNode.APIVERSION, DockerNode.defaultApi);
        }

        service.saveEndpointConfiguration(config);

        // Invalidate the plugin-inventory by calling notifyElementsInvalidate
        // This will trigger 'sdk-invalidate' on object 'Coopto'
        log.debug("Reloading inventory...");
        notificationHandler.notifyElementsInvalidate();

        log.debug("Finished running createNode().");
    } catch (IOException e) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        e.printStackTrace(pw);
        log.error("Error: " + sw.getBuffer().toString());
    }
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParserTest.java

private void assertHasThrowable(StringWriter capture, Class<? extends Throwable> t) {
    String buf = capture.getBuffer().toString();
    Assert.assertThat(buf, containsString(t.getSimpleName()));
}

From source file:org.apache.taverna.configuration.AbstractConfigurable.java

private String toListText(List<String> values) {
    StringWriter writer = new StringWriter();
    CSVPrinter csvWriter = new CSVPrinter(writer);
    csvWriter.println(values.toArray(new String[] {}));
    return writer.getBuffer().toString().trim();
}

From source file:nl.nn.adapterframework.batch.ResultBlock2Sender.java

public void closeBlock(IPipeLineSession session, String streamId, String blockName,
        ParameterResolutionContext prc) throws Exception {
    super.closeBlock(session, streamId, blockName, prc);
    int level = decLevel(streamId);
    if (level == 0) {
        StringWriter writer = (StringWriter) getWriter(session, streamId, false, prc);
        if (writer != null) {
            String message = writer.getBuffer().toString();
            log.debug("sending block [" + message + "] to sender [" + sender.getName() + "]");
            writer.getBuffer().setLength(0);
            ISender sender = getSender();
            if (sender instanceof ISenderWithParameters) {
                ISenderWithParameters psender = (ISenderWithParameters) sender;
                psender.sendMessage(streamId + "-" + incCounter(streamId), message, prc);
            } else {
                sender.sendMessage(streamId + "-" + incCounter(streamId), message);
            }/*from www. ja v  a  2 s  .  c o m*/
        }
    }
}

From source file:com.xinferin.licensing.LicenceGenerator.java

/**
 * Gets an RSA public key as String/*from  w  ww  .j av a 2 s.  co m*/
 * @param key
 * @return
 * @throws UnsupportedEncodingException
 * @throws ParserConfigurationException
 * @throws TransformerException
 */
private String getRSAPublicKeyAsXMLString(RSAPublicKey key)
        throws UnsupportedEncodingException, ParserConfigurationException, TransformerException {
    Document xml = getRSAPublicKeyAsXML(key);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    StringWriter sw = new StringWriter();
    transformer.transform(new DOMSource(xml), new StreamResult(sw));

    return sw.getBuffer().toString();
}

From source file:net.sf.reportengine.components.TestReportTitleComponent.java

@Test
public void testOutputNewReportOutput() {
    StringWriter testWriter = new StringWriter();
    MockReportOutput testOutput = new MockReportOutput(testWriter);
    componentUnderTest = new ReportTitle("unit test");
    testOutput.open();//from w  w  w . j a  v a 2s  .  c  o m
    componentUnderTest.output(testOutput);
    testOutput.close();
    assertEquals("title unit test", testWriter.getBuffer().toString());
}

From source file:org.dswarm.xsd2jsonschema.model.JSRoot.java

public String render() throws IOException {
    final JsonFactory jsonFactory = new JsonFactory();
    final StringWriter writer = new StringWriter();

    final JsonGenerator generator = jsonFactory.createGenerator(writer);
    generator.setPrettyPrinter(new DefaultPrettyPrinter());

    render(generator);/*from   w w  w  .j  a  va  2 s.co m*/

    return writer.getBuffer().toString();
}

From source file:com.moss.veracity.core.cluster.jms.UpdateTransmitterJMSImpl.java

private void sendMessage(Object o) {

    Session session = null;/*from w  w  w.j  av  a  2 s. c  o  m*/
    MessageProducer producer = null;
    try {
        StringWriter writer = new StringWriter();
        Marshaller m = jaxbContext.createMarshaller();
        m.marshal(o, writer);
        String text = writer.getBuffer().toString();

        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(UpdateTopic.NAME);
        producer = session.createProducer(topic);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);

        TextMessage message = session.createTextMessage(text);
        producer.send(message);

        producer.close();
        session.close();
    } catch (Exception ex) {

        if (producer != null) {
            try {
                producer.close();
            } catch (JMSException e) {
                if (log.isErrorEnabled()) {
                    log.error("Failed to close producer after failure", e);
                } else {
                    ex.printStackTrace();
                }
            }
        }

        if (session != null) {
            try {
                session.close();
            } catch (JMSException e) {
                if (log.isErrorEnabled()) {
                    log.error("Failed to close session after failure", e);
                } else {
                    ex.printStackTrace();
                }
            }
        }

        throw new RuntimeException("Message transmission failed: " + o, ex);
    }
}

From source file:cn.com.sinosoft.util.exception.ExceptionUtils.java

/**
 * <p>//  w  ww . j a v a2 s  . c  om
 * Gets the stack trace from a Throwable as a String.
 * </p>
 * 
 * <p>
 * The result of this method vary by JDK version as this method uses
 * {@link Throwable#printStackTrace(java.io.PrintWriter)}. On JDK1.3 and
 * earlier, the cause exception will not be shown unless the specified
 * throwable alters printStackTrace.
 * </p>
 * 
 * @param throwable
 *            the <code>Throwable</code> to be examined
 * @return the stack trace as generated by the exception's
 *         <code>printStackTrace(PrintWriter)</code> method
 */
public static String getStackTrace(Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    throwable.printStackTrace(pw);
    return sw.getBuffer().toString();
}