public static void main(String[] args) throws Exception {
IoBuffer opening = IoBuffer.wrap("<p:root xmlns:p='http://example.com'>".getBytes("UTF-8"));
IoBuffer buffer = IoBuffer.wrap(SINGLE_LEVEL_XML.getBytes("UTF-8"));
DefaultNonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();
CounterStanzaListener listener = new CounterStanzaListener();
XMPPContentHandler contentHandler = new XMPPContentHandler();
contentHandler.setListener(listener);
reader.setContentHandler(contentHandler);
StopWatch watch = new StopWatch();
reader.parse(opening, CharsetUtil.UTF8_DECODER);
for (int i = 0; i < 10000; i++) {
buffer.position(0);
reader.parse(buffer, CharsetUtil.UTF8_DECODER);
}
watch.stop();
System.out.println(listener.counter + " stanzas parsed");
System.out.println(watch);