Class XmlReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    public final class XmlReader
    extends java.io.Reader
    This is a simple XmlReader. Its only purpose is to read the xml decl string from the input and apply proper character encoding to all subsequent characters. The xml decl string itself is removed from the output.
    Author:
    Juergen Donnerstag
    • Field Summary

      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlReader​(java.io.InputStream inputStream, java.lang.String defaultEncoding)
      Construct.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.lang.String getEncoding()
      Return the encoding used while reading the markup file.
      void init()
      Reads and parses markup from a resource such as file.
      int read​(char[] buf, int from, int to)  
      java.lang.String toString()  
      • Methods inherited from class java.io.Reader

        mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • XmlReader

        public XmlReader​(java.io.InputStream inputStream,
                         java.lang.String defaultEncoding)
                  throws java.io.IOException
        Construct.
        Parameters:
        inputStream - The InputStream to read the xml data from
        defaultEncoding - Default character encoding to use when not specified in XML declaration, specify null to use JVM default
        Throws:
        java.io.IOException - In case something went wrong while reading the data
    • Method Detail

      • getEncoding

        public final java.lang.String getEncoding()
        Return the encoding used while reading the markup file.
        Returns:
        if null, then JVM default
      • init

        public void init()
                  throws java.io.IOException
        Reads and parses markup from a resource such as file.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException
        See Also:
        Reader.close()
      • read

        public int read​(char[] buf,
                        int from,
                        int to)
                 throws java.io.IOException
        Specified by:
        read in class java.io.Reader
        Throws:
        java.io.IOException
        See Also:
        Reader.read(char[], int, int)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        The markup to be parsed