Class Utf32Reader

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

    public class Utf32Reader
    extends java.io.Reader
    Since JDK does not come with UTF-32/UCS-4, let's implement a simple decoder to use.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean mBigEndian  
      protected byte[] mBuffer  
      protected int mByteCount
      Total read byte count; used for error reporting purposes
      protected int mCharCount
      Total read character count; used for error reporting purposes
      protected ReaderConfig mConfig  
      protected java.io.InputStream mIn  
      protected int mLength  
      protected int mPtr  
      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.
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      Utf32Reader​(ReaderConfig cfg, java.io.InputStream in, byte[] buf, int ptr, int len, boolean isBigEndian)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void freeBuffers()  
      int read()
      Although this method is implemented by the base class, AND it should never be called by Woodstox code, let's still implement it bit more efficiently just in case
      int read​(char[] cbuf, int start, int len)  
      protected void reportBounds​(char[] cbuf, int start, int len)  
      protected void reportStrangeStream()  
      • Methods inherited from class java.io.Reader

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

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

      • mIn

        protected java.io.InputStream mIn
      • mBuffer

        protected byte[] mBuffer
      • mPtr

        protected int mPtr
      • mLength

        protected int mLength
      • mBigEndian

        protected final boolean mBigEndian
      • 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 isBigEndian)
    • Method Detail

      • 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()
                 throws java.io.IOException
        Although this method is implemented by the base class, AND it should never be called by Woodstox code, let's still implement it bit more efficiently just in case
        Overrides:
        read in class java.io.Reader
        Throws:
        java.io.IOException
      • 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
      • freeBuffers

        public final void freeBuffers()
      • reportBounds

        protected void reportBounds​(char[] cbuf,
                                    int start,
                                    int len)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • reportStrangeStream

        protected void reportStrangeStream()
                                    throws java.io.IOException
        Throws:
        java.io.IOException