Search in sources :

Example 1 with StAXDialect

use of org.apache.axiom.util.stax.dialect.StAXDialect in project webservices-axiom by apache.

the class StreamingOMSerializerTest method runTest.

@Override
protected void runTest() throws Throwable {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    StAXDialect dialect = StAXDialectDetector.getDialect(inputFactory.getClass());
    inputFactory = dialect.normalize(inputFactory);
    // Allow CDATA events
    inputFactory = dialect.enableCDataReporting(inputFactory);
    inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
    XMLOutputFactory outputFactory = dialect.normalize(XMLOutputFactory.newInstance());
    StreamingOMSerializer serializer = new StreamingOMSerializer();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new StreamSource(file.getUrl().toString()));
    String encoding = reader.getEncoding();
    XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, encoding);
    writer.writeStartDocument(encoding, reader.getVersion());
    serializer.serialize(reader, writer, false);
    writer.writeEndDocument();
    writer.flush();
    InputSource actual = new InputSource();
    actual.setByteStream(new ByteArrayInputStream(out.toByteArray()));
    actual.setSystemId(file.getUrl().toString());
    assertAbout(xml()).that(actual).hasSameContentAs(file.getUrl());
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamSource(javax.xml.transform.stream.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StAXDialect(org.apache.axiom.util.stax.dialect.StAXDialect) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 StreamSource (javax.xml.transform.stream.StreamSource)1 StAXDialect (org.apache.axiom.util.stax.dialect.StAXDialect)1 InputSource (org.xml.sax.InputSource)1