Class XMLInputStreamReader

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

    public class XMLInputStreamReader
    extends java.io.Reader
    Determine the encoding of a stream of bytes according to the XML spec and return a Reader which converts the byte stream into Unicode as it is read.
    See Also:
    Reader
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.Reader delegate  
      static java.lang.String ENCODING_ISO_8859_1
      The constant "ISO-8859-1", also called "Latin-1"
      static java.lang.String ENCODING_ISO_Latin_1
      An alias for ENCODING_ISO_8859_1
      static java.util.Map<java.lang.String,​java.lang.String> ENCODING_MAP
      A map to convert standard XML encodings into Java encodings.
      static java.lang.String ENCODING_UTF_8
      The constant "UTF-8"
      private java.io.InputStream in  
      static java.util.Map<java.lang.String,​java.lang.String> JAVA_TO_XML_ENCODING_MAP
      A map to convert standard Java encodings into XML encodings.
      private java.lang.String javaEncoding  
      static java.util.regex.Pattern VERSION_PATTERN  
      private java.lang.String xmlEncoding  
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLInputStreamReader​(java.io.InputStream in)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void determineEncoding()
      Determine the encoding of the stream.
      java.lang.String getJavaEncoding()
      Get the Java name of the XML encoding of the stream.
      java.lang.String getXmlEncoding()
      Return the encoding of the stream
      int read​(char[] cbuf, int off, int len)  
      void setXmlEncoding​(java.lang.String xmlEncoding)
      If you know the encoding, you can override it here.
      • Methods inherited from class java.io.Reader

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

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

      • ENCODING_UTF_8

        public static final java.lang.String ENCODING_UTF_8
        The constant "UTF-8"
        See Also:
        Constant Field Values
      • ENCODING_ISO_8859_1

        public static final java.lang.String ENCODING_ISO_8859_1
        The constant "ISO-8859-1", also called "Latin-1"
        See Also:
        Constant Field Values
      • ENCODING_ISO_Latin_1

        public static final java.lang.String ENCODING_ISO_Latin_1
        An alias for ENCODING_ISO_8859_1
        See Also:
        Constant Field Values
      • ENCODING_MAP

        public static java.util.Map<java.lang.String,​java.lang.String> ENCODING_MAP
        A map to convert standard XML encodings into Java encodings.

        The map is mutable; you can put your own encodings in here if you need them.

      • JAVA_TO_XML_ENCODING_MAP

        public static java.util.Map<java.lang.String,​java.lang.String> JAVA_TO_XML_ENCODING_MAP
        A map to convert standard Java encodings into XML encodings.

        The map is mutable; you can put your own encodings in here if you need them.

      • in

        private java.io.InputStream in
      • xmlEncoding

        private java.lang.String xmlEncoding
      • javaEncoding

        private java.lang.String javaEncoding
      • delegate

        private java.io.Reader delegate
      • VERSION_PATTERN

        public static final java.util.regex.Pattern VERSION_PATTERN
    • Constructor Detail

      • XMLInputStreamReader

        public XMLInputStreamReader​(java.io.InputStream in)
    • Method Detail

      • determineEncoding

        public void determineEncoding()
        Determine the encoding of the stream.

        It is safe to call this method more than once from a single thread.

      • getXmlEncoding

        public java.lang.String getXmlEncoding()
        Return the encoding of the stream
      • setXmlEncoding

        public void setXmlEncoding​(java.lang.String xmlEncoding)
        If you know the encoding, you can override it here.

        When you do that, the reader will ignore the encoding in the stream if there is one.

      • getJavaEncoding

        public java.lang.String getJavaEncoding()
        Get the Java name of the XML encoding of the stream.
      • 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
      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
                 throws java.io.IOException
        Specified by:
        read in class java.io.Reader
        Throws:
        java.io.IOException