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());
}
Aggregations