Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XMLStreamReader and InputStream

843834Apr 16 2010 — edited Apr 16 2010
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2010
Added on Apr 16 2010
3 comments
1,054 views