Search in sources :

Example 1 with JsonWriter

use of nl.nn.adapterframework.stream.json.JsonWriter in project iaf by ibissource.

the class MessageOutputStream method captureBinaryStream.

@SuppressWarnings("resource")
public void captureBinaryStream(OutputStream outputStream, int maxSize) {
    log.debug("creating capture of " + ClassUtils.nameOf(requestStream));
    closeOnClose(outputStream);
    if (requestStream instanceof OutputStream) {
        requestStream = StreamUtil.captureOutputStream((OutputStream) requestStream, outputStream, maxSize);
        return;
    }
    if (requestStream instanceof ContentHandler) {
        requestStream = new XmlTee((ContentHandler) requestStream, new PrettyPrintFilter(new XmlWriter(StreamUtil.limitSize(outputStream, maxSize))));
        return;
    }
    if (requestStream instanceof JsonEventHandler) {
        requestStream = new JsonTee((JsonEventHandler) requestStream, new JsonWriter(StreamUtil.limitSize(outputStream, maxSize)));
        return;
    }
    if (requestStream instanceof Writer) {
        requestStream = StreamUtil.captureWriter((Writer) requestStream, new OutputStreamWriter(outputStream, StreamUtil.DEFAULT_CHARSET), maxSize);
        return;
    }
    log.warn("captureBinaryStream() called before stream is installed.");
}
Also used : XmlTee(nl.nn.adapterframework.stream.xml.XmlTee) JsonTee(nl.nn.adapterframework.stream.json.JsonTee) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) ContentHandler(org.xml.sax.ContentHandler) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Example 2 with JsonWriter

use of nl.nn.adapterframework.stream.json.JsonWriter in project iaf by ibissource.

the class MessageOutputStream method captureCharacterStream.

@SuppressWarnings("resource")
public void captureCharacterStream(Writer writer, int maxSize) {
    log.debug("creating capture of " + ClassUtils.nameOf(requestStream));
    closeOnClose(writer);
    if (requestStream instanceof Writer) {
        requestStream = StreamUtil.captureWriter((Writer) requestStream, writer, maxSize);
        return;
    }
    if (requestStream instanceof ContentHandler) {
        requestStream = new XmlTee((ContentHandler) requestStream, new PrettyPrintFilter(new XmlWriter(StreamUtil.limitSize(writer, maxSize))));
        return;
    }
    if (requestStream instanceof JsonEventHandler) {
        requestStream = new JsonTee((JsonEventHandler) requestStream, new JsonWriter(StreamUtil.limitSize(writer, maxSize)));
        return;
    }
    if (requestStream instanceof OutputStream) {
        requestStream = StreamUtil.captureOutputStream((OutputStream) requestStream, new WriterOutputStream(writer, StreamUtil.DEFAULT_CHARSET), maxSize);
        return;
    }
    log.warn("captureCharacterStream() called before stream is installed.");
}
Also used : XmlTee(nl.nn.adapterframework.stream.xml.XmlTee) JsonTee(nl.nn.adapterframework.stream.json.JsonTee) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) ContentHandler(org.xml.sax.ContentHandler) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Example 3 with JsonWriter

use of nl.nn.adapterframework.stream.json.JsonWriter in project iaf by ibissource.

the class DocumentBuilderTest method testJsonDocumentBuilder.

@Test
public void testJsonDocumentBuilder() throws SAXException {
    String expected = expectedJson;
    JsonWriter writer = new JsonWriter();
    try (IDocumentBuilder root = new JsonDocumentBuilder(writer)) {
        buildDocument(root);
    }
    // MatchUtils.assertJsonEqual("", expected, root.getRoot().toString());
    assertEquals(expected, writer.toString());
}
Also used : JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) Test(org.junit.Test)

Aggregations

JsonWriter (nl.nn.adapterframework.stream.json.JsonWriter)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 JsonTee (nl.nn.adapterframework.stream.json.JsonTee)2 XmlTee (nl.nn.adapterframework.stream.xml.XmlTee)2 PrettyPrintFilter (nl.nn.adapterframework.xml.PrettyPrintFilter)2 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 ContentHandler (org.xml.sax.ContentHandler)2 Test (org.junit.Test)1