Class StreamReader

  • All Implemented Interfaces:
    EventReader

    class StreamReader
    extends java.lang.Object
    implements EventReader
    The StreamReader object provides an implementation for reading XML events using StAX. This will pretty much wrap core StAX events as the framework is very closely related. The implementation is basically required to ensure StAX events can be digested by the core reader. For performance this will match the underlying implementation closely as all this basically does is act as a means to adapt the underlying framework events.
    See Also:
    StreamProvider
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  StreamReader.End
      The End object is used to represent the end of an element.
      private static class  StreamReader.Entry
      The Entry object is used to represent an attribute within a start element.
      private static class  StreamReader.Start
      The Start object is used to represent the start of an XML element.
      private static class  StreamReader.Text
      The Text object is used to represent a text event.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private EventNode peek
      This is used to keep track of any events that were peeked.
      private javax.xml.stream.XMLEventReader reader
      This is the reader that is used to parse the XML document.
    • Constructor Summary

      Constructors 
      Constructor Description
      StreamReader​(javax.xml.stream.XMLEventReader reader)
      Constructor for the StreamReader object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private StreamReader.Entry attribute​(javax.xml.stream.events.Attribute entry)
      This is used to convert the provided object to an attribute.
      private StreamReader.Start build​(StreamReader.Start event)
      This is used to build the attributes that are to be used to populate the start event.
      private StreamReader.End end()
      This is used to create an event to signify that an element has just ended.
      EventNode next()
      This is used to take the next node from the document.
      EventNode peek()
      This is used to peek at the node from the document.
      private EventNode read()
      This is used to read the next node from the document.
      private StreamReader.Start start​(javax.xml.stream.events.XMLEvent event)
      This is used to convert the provided event to a start event.
      private StreamReader.Text text​(javax.xml.stream.events.XMLEvent event)
      This is used to convert the provided event to a text event.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • reader

        private javax.xml.stream.XMLEventReader reader
        This is the reader that is used to parse the XML document.
      • peek

        private EventNode peek
        This is used to keep track of any events that were peeked.
    • Constructor Detail

      • StreamReader

        public StreamReader​(javax.xml.stream.XMLEventReader reader)
        Constructor for the StreamReader object. This creates a reader that extracts events from the provided object. All StAX events returned from the provided instance will be adapted so that they can be digested by the core reader.
        Parameters:
        reader - this is the reader used to parse the XML source
    • Method Detail

      • peek

        public EventNode peek()
                       throws java.lang.Exception
        This is used to peek at the node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
        Specified by:
        peek in interface EventReader
        Returns:
        this returns the next event taken from the document
        Throws:
        java.lang.Exception
      • next

        public EventNode next()
                       throws java.lang.Exception
        This is used to take the next node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
        Specified by:
        next in interface EventReader
        Returns:
        this returns the next event taken from the source XML
        Throws:
        java.lang.Exception
      • read

        private EventNode read()
                        throws java.lang.Exception
        This is used to read the next node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
        Returns:
        this returns the next event taken from the document
        Throws:
        java.lang.Exception
      • start

        private StreamReader.Start start​(javax.xml.stream.events.XMLEvent event)
        This is used to convert the provided event to a start event. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent an XML elements within the source document.
        Parameters:
        event - the event that is to be converted to a start event
        Returns:
        this returns a start event created from the given event
      • build

        private StreamReader.Start build​(StreamReader.Start event)
        This is used to build the attributes that are to be used to populate the start event. Populating the start event with the attributes it contains is required so that each element will contain its associated attributes. Only attributes that are not reserved will be added to the start event.
        Parameters:
        event - this is the start event that is to be populated
        Returns:
        this returns a start event with its attributes
      • attribute

        private StreamReader.Entry attribute​(javax.xml.stream.events.Attribute entry)
        This is used to convert the provided object to an attribute. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent an XML attribute within the source document.
        Parameters:
        entry - the object that is to be converted to an attribute
        Returns:
        this returns an attribute created from the given object
      • text

        private StreamReader.Text text​(javax.xml.stream.events.XMLEvent event)
        This is used to convert the provided event to a text event. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent an XML attribute within the source document.
        Parameters:
        event - the event that is to be converted to a text event
        Returns:
        this returns the text event created from the given event
      • end

        private StreamReader.End end()
        This is used to create an event to signify that an element has just ended. End events are important as they allow the core reader to determine if a node is still in context. This provides a more convenient way to use InputNode objects as they should only ever be able to extract their children.
        Returns:
        this returns an end event to signify an element close