Hello.
I'm trying to use XMLStreamReader (StAX) in this way:
PipedOutputStream output = new PipedOutputStream();
InputStream input = new PipedInputStream(output, 1024);
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(input, "UTF-8");
// XMLStreamReader should already be created and "ready for input data". And now I'm feeding data to it:
output.write("<?xml version=\"1.0\"?><root></root>".getBytes("UTF-8"));
while (streamReader.hasNext()) {
System.out.printf("event is %d%n", streamReader.next());
}
Question is, why #createXMLStreamReader() tries to read the input buffer (and blocks)? Shouldn't it only try to read on next/hasNext operations? Apparently I'm not using it properly, but I can't figure out why. I think I should create a stream reader, and then sometime, in the future, when data becomes available, the given InputStream will start giving out bytes to the reader, right? That's the idea of stream processing. In other words, how do I feed input bytes to the XMLStreamReader chunk by chunk?
Thanks for help,
Yuri.