Example usage for java.io StringWriter flush

List of usage examples for java.io StringWriter flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flush the stream.

Usage

From source file:org.apache.olingo.client.core.it.AbstractTestITCase.java

protected void debugODataEntity(final ODataEntity entity, final String message) {
    if (LOG.isDebugEnabled()) {
        StringWriter writer = new StringWriter();
        getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, AtomEntryImpl.class),
                writer);// w w w  .  j a va2 s .c  o  m
        writer.flush();
        LOG.debug(message + " (Atom)\n{}", writer.toString());

        writer = new StringWriter();
        getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, JSONEntryImpl.class),
                writer);
        writer.flush();
        LOG.debug(message + " (JSON)\n{}", writer.toString());
    }
}

From source file:com.msopentech.odatajclient.engine.it.AbstractTest.java

protected void debugODataEntity(final ODataEntity entity, final String message) {
    if (LOG.isDebugEnabled()) {
        StringWriter writer = new StringWriter();
        client.getSerializer().entry(client.getBinder().getEntry(entity, AtomEntry.class), writer);
        writer.flush();
        LOG.debug(message + " (Atom)\n{}", writer.toString());

        writer = new StringWriter();
        client.getSerializer().entry(client.getBinder().getEntry(entity, JSONV3Entry.class), writer);
        writer.flush();//  w w w . ja va 2  s. c  o  m
        LOG.debug(message + " (JSON)\n{}", writer.toString());
    }
}

From source file:org.etudes.component.app.melete.SubSectionUtilImpl.java

private String writeDocumentToString(org.w3c.dom.Document doc) {
    try {/*from  w  w w  . j a  va 2 s  .c o m*/
        StringWriter sw = new StringWriter();
        // Note: using xerces %%% is there a org.w3c.dom way to do this?
        XMLSerializer s = new XMLSerializer(sw, new OutputFormat("xml", "UTF-8", false));
        s.serialize(doc);

        sw.flush();
        return sw.toString();
    } catch (Exception any) {
        logger.warn("writeDocumentToString: " + any.toString());
        return null;
    }
}

From source file:org.deventropy.junithelper.derby.SimpleDerbyScriptRunnerTest.java

@Test
public void testLoggingChanges() throws SQLException, IOException {

    final StringWriter logData1 = new StringWriter();
    final WriterOutputStream wos1 = new WriterOutputStream(logData1, Charset.defaultCharset());

    final StringWriter logData2 = new StringWriter();
    final WriterOutputStream wos2 = new WriterOutputStream(logData2, Charset.defaultCharset());

    Connection connection = null;

    try {/* w  w w  .  ja v  a2 s  . c om*/
        connection = DriverManager.getConnection(embeddedDerbyResource.getJdbcUrl());
        final DerbyScriptRunner scriptRunner = new DerbyScriptRunner(connection);

        scriptRunner.setDefaultScriptLogStream(wos1);

        // Run one with a output stream here
        scriptRunner.executeScript("classpath:/org/deventropy/junithelper/derby/simple01/ddl.sql", wos2, true);
        logData2.flush();
        assertTrue("Expected log doesnt exist", logData2.toString().contains("rows inserted/updated/deleted"));
        assertTrue("Should have nothing in the default", logData1.toString().isEmpty());

        scriptRunner.executeScript("classpath:/org/deventropy/junithelper/derby/simple01/dml.sql");

        wos1.flush();
        logData1.flush();

        assertTrue("Expected log doesnt exist", logData1.toString().contains("row inserted/updated/deleted"));
    } finally {
        DerbyUtils.closeQuietly(connection);
    }
}

From source file:com.msopentech.odatajclient.engine.it.AbstractTestITCase.java

protected void debugODataEntity(final ODataEntity entity, final String message) {
    if (LOG.isDebugEnabled()) {
        StringWriter writer = new StringWriter();
        client.getSerializer().entry(client.getBinder().getEntry(entity, AtomEntry.class), writer);
        writer.flush();
        LOG.debug(message + " (Atom)\n{}", writer.toString());

        writer = new StringWriter();
        client.getSerializer().entry(client.getBinder().getEntry(entity, JSONEntry.class), writer);
        writer.flush();//w  ww.  j  a  v a 2 s.c  om
        LOG.debug(message + " (JSON)\n{}", writer.toString());
    }
}

From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java

/**
 * Utility to serialize Document as a String for debugging
 *
 * @param document document//ww  w .j  a  v a 2s .  co  m
 *
 * @return xml string
 *
 * @throws java.io.IOException if error occurs
 */
private static String serialize(final Document document) throws IOException {
    final OutputFormat format = OutputFormat.createPrettyPrint();
    final StringWriter sw = new StringWriter();
    final XMLWriter writer = new XMLWriter(sw, format);
    writer.write(document);
    writer.flush();
    sw.flush();
    return sw.toString();
}

From source file:org.apache.axis2.description.AxisDescriptionBase.java

public String getDocumentation() {
    if (documentation != null) {
        if (documentation.getType() == OMNode.TEXT_NODE) {
            return ((OMText) documentation).getText();
        } else {//from   w w w.  j  a v a2s.  c o  m
            StringWriter writer = new StringWriter();
            documentation.build();
            try {
                documentation.serialize(writer);
            } catch (XMLStreamException e) {
                log.error(e);
            }
            writer.flush();
            return writer.toString();
        }
    }
    return null;
}

From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java

@Override
public ODataEntity getODataEntity(final EntryResource resource, final URI defaultBaseURI) {
    if (LOG.isDebugEnabled()) {
        final StringWriter writer = new StringWriter();
        client.getSerializer().entry(resource, writer);
        writer.flush();
        LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString());
    }//w ww.j  a va 2  s . c  o  m

    final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;

    final ODataEntity entity = resource.getSelfLink() == null ? ODataObjectFactory.newEntity(resource.getType())
            : ODataObjectFactory.newEntity(resource.getType(),
                    URIUtils.getURI(base, resource.getSelfLink().getHref()));

    if (StringUtils.isNotBlank(resource.getETag())) {
        entity.setETag(resource.getETag());
    }

    if (resource.getEditLink() != null) {
        entity.setEditLink(URIUtils.getURI(base, resource.getEditLink().getHref()));
    }

    for (LinkResource link : resource.getAssociationLinks()) {
        entity.addLink(ODataObjectFactory.newAssociationLink(link.getTitle(), base, link.getHref()));
    }

    for (LinkResource link : resource.getNavigationLinks()) {
        final EntryResource inlineEntry = link.getInlineEntry();
        final FeedResource inlineFeed = link.getInlineFeed();

        if (inlineEntry == null && inlineFeed == null) {
            entity.addLink(ODataObjectFactory.newEntityNavigationLink(link.getTitle(), base, link.getHref()));
        } else if (inlineFeed == null) {
            entity.addLink(
                    ODataObjectFactory.newInlineEntity(link.getTitle(), base, link.getHref(), getODataEntity(
                            inlineEntry, inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI())));
        } else {
            entity.addLink(ODataObjectFactory.newInlineEntitySet(link.getTitle(), base, link.getHref(),
                    getODataEntitySet(inlineFeed,
                            inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI())));
        }
    }

    for (LinkResource link : resource.getMediaEditLinks()) {
        entity.addLink(ODataObjectFactory.newMediaEditLink(link.getTitle(), base, link.getHref()));
    }

    for (ODataOperation operation : resource.getOperations()) {
        operation.setTarget(URIUtils.getURI(base, operation.getTarget()));
        entity.addOperation(operation);
    }

    final Element content;
    if (resource.isMediaEntry()) {
        entity.setMediaEntity(true);
        entity.setMediaContentSource(resource.getMediaContentSource());
        entity.setMediaContentType(resource.getMediaContentType());
        content = resource.getMediaEntryProperties();
    } else {
        content = resource.getContent();
    }
    if (content != null) {
        for (Node property : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) {
            try {
                entity.addProperty(getProperty((Element) property));
            } catch (IllegalArgumentException e) {
                LOG.warn("Failure retrieving EdmType for {}", property.getTextContent(), e);
            }
        }
    }

    return entity;
}

From source file:com.msopentech.odatajclient.engine.data.impl.AbstractODataBinder.java

@Override
public ODataEntity getODataEntity(final Entry resource, final URI defaultBaseURI) {
    if (LOG.isDebugEnabled()) {
        final StringWriter writer = new StringWriter();
        client.getSerializer().entry(resource, writer);
        writer.flush();
        LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString());
    }/*from  w  w  w . ja  v  a  2s  . c o  m*/

    final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI;

    final ODataEntity entity = resource.getSelfLink() == null
            ? client.getObjectFactory().newEntity(resource.getType())
            : client.getObjectFactory().newEntity(resource.getType(),
                    URIUtils.getURI(base, resource.getSelfLink().getHref()));

    if (StringUtils.isNotBlank(resource.getETag())) {
        entity.setETag(resource.getETag());
    }

    if (resource.getEditLink() != null) {
        entity.setEditLink(URIUtils.getURI(base, resource.getEditLink().getHref()));
    }

    for (Link link : resource.getAssociationLinks()) {
        entity.addLink(client.getObjectFactory().newAssociationLink(link.getTitle(), base, link.getHref()));
    }

    for (Link link : resource.getNavigationLinks()) {
        final Entry inlineEntry = link.getInlineEntry();
        final Feed inlineFeed = link.getInlineFeed();

        if (inlineEntry == null && inlineFeed == null) {
            entity.addLink(
                    client.getObjectFactory().newEntityNavigationLink(link.getTitle(), base, link.getHref()));
        } else if (inlineFeed == null) {
            entity.addLink(client.getObjectFactory().newInlineEntity(link.getTitle(), base, link.getHref(),
                    getODataEntity(inlineEntry,
                            inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI())));
        } else {
            entity.addLink(client.getObjectFactory().newInlineEntitySet(link.getTitle(), base, link.getHref(),
                    getODataEntitySet(inlineFeed,
                            inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI())));
        }
    }

    for (Link link : resource.getMediaEditLinks()) {
        entity.addLink(client.getObjectFactory().newMediaEditLink(link.getTitle(), base, link.getHref()));
    }

    for (ODataOperation operation : resource.getOperations()) {
        operation.setTarget(URIUtils.getURI(base, operation.getTarget()));
        entity.addOperation(operation);
    }

    final Element content;
    if (resource.isMediaEntry()) {
        entity.setMediaEntity(true);
        entity.setMediaContentSource(resource.getMediaContentSource());
        entity.setMediaContentType(resource.getMediaContentType());
        content = resource.getMediaEntryProperties();
    } else {
        content = resource.getContent();
    }
    if (content != null) {
        for (Node property : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) {
            try {
                entity.addProperty(getProperty((Element) property));
            } catch (IllegalArgumentException e) {
                LOG.warn("Failure retrieving EdmType for {}", property.getTextContent(), e);
            }
        }
    }

    return entity;
}

From source file:de.mogwai.common.web.component.renderkit.html.common.TableRenderer.java

protected void renderChildAndCheckEmptyness(FacesContext aContext, UIComponent aComponent) throws IOException {

    ResponseWriter theWriter = aContext.getResponseWriter();

    StringWriter theStringWriter = new StringWriter();
    ResponseWriter theBufferedWriter = theWriter.cloneWithWriter(theStringWriter);
    aContext.setResponseWriter(theBufferedWriter);

    if (aComponent != null) {
        RendererUtils.renderChild(aContext, aComponent);
    }// w  w w  .j  a va  2 s . c o m

    aContext.setResponseWriter(theWriter);

    theStringWriter.flush();
    StringBuffer theContent = stripCommentsFromString(theStringWriter.getBuffer());
    if (theContent.length() > 0) {
        theWriter.write(theContent.toString());
    } else {
        theWriter.write("<div style=\"width:1px; height:1px;\"></div>");
    }

}