use of org.openexi.sax.EXIReader in project ddf by codice.
the class EXIEncoderTest method testEncode.
/**
* Tests that the encode method converts xml into exi-compressed xml.
*
* @throws Exception
*/
@Test
public void testEncode() throws Exception {
ByteArrayOutputStream exiStream = new ByteArrayOutputStream();
InputStream xmlStream = getClass().getResourceAsStream(TEST_FILE);
EXIEncoder.encode(xmlStream, exiStream);
StringWriter stringWriter = new StringWriter();
GrammarCache grammarCache;
SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
TransformerHandler transformerHandler = saxTransformerFactory.newTransformerHandler();
EXIReader reader = new EXIReader();
grammarCache = new GrammarCache(null, GrammarOptions.DEFAULT_OPTIONS);
reader.setGrammarCache(grammarCache);
transformerHandler.setResult(new StreamResult(stringWriter));
reader.setContentHandler(transformerHandler);
reader.parse(new InputSource(new ByteArrayInputStream(exiStream.toByteArray())));
XMLUnit.setNormalize(true);
XMLUnit.setNormalizeWhitespace(true);
InputStream stream = getClass().getResourceAsStream(TEST_FILE);
Diff diff = XMLUnit.compareXML(IOUtils.toString(stream), stringWriter.getBuffer().toString());
IOUtils.closeQuietly(stream);
assertTrue("The XML input file (" + TEST_FILE + ") did not match the EXI-decoded output", diff.similar());
}
Aggregations