Class UTF32Reader

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

    public final class UTF32Reader
    extends BaseReader
    Since JDK does not come with UTF-32/UCS-4, let's implement a simple decoder to use.
    • Field Detail

      • mBigEndian

        protected final boolean mBigEndian
      • mXml11

        protected boolean mXml11
      • mSurrogate

        protected char mSurrogate
        Although input is fine with full Unicode set, Java still uses 16-bit chars, so we may have to split high-order chars into surrogate pairs.
      • mCharCount

        protected int mCharCount
        Total read character count; used for error reporting purposes
      • mByteCount

        protected int mByteCount
        Total read byte count; used for error reporting purposes
    • Constructor Detail

      • UTF32Reader

        public UTF32Reader​(ReaderConfig cfg,
                           java.io.InputStream in,
                           byte[] buf,
                           int ptr,
                           int len,
                           boolean recycleBuffer,
                           boolean isBigEndian)
    • Method Detail

      • setXmlCompliancy

        public void setXmlCompliancy​(int xmlVersion)
        Description copied from class: BaseReader
        Method that can be called to indicate the xml conformance used when reading content using this reader. Some of the character validity checks need to be done at reader level, and sometimes they depend on xml level (for example, xml 1.1 has new linefeeds and both more and less restricted characters).
        Specified by:
        setXmlCompliancy in class BaseReader
      • read

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

        private void reportUnexpectedEOF​(int gotBytes,
                                         int needed)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • reportInvalid

        private void reportInvalid​(int value,
                                   int offset,
                                   java.lang.String msg)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • loadMore

        private boolean loadMore​(int available)
                          throws java.io.IOException
        Parameters:
        available - Number of "unused" bytes in the input buffer
        Returns:
        True, if enough bytes were read to allow decoding of at least one full character; false if EOF was encountered instead.
        Throws:
        java.io.IOException