Class UTF32Reader

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Readable

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

      • LAST_VALID_UNICODE_CHAR

        protected static final int LAST_VALID_UNICODE_CHAR
        JSON actually limits available Unicode range in the high end to the same as xml (to basically limit UTF-8 max byte sequence length to 4)
        See Also:
        Constant Field Values
      • _context

        protected final IOContext _context
      • _buffer

        protected byte[] _buffer
      • _ptr

        protected int _ptr
      • _length

        protected int _length
      • _tmpBuf

        protected char[] _tmpBuf
    • Constructor Detail

      • UTF32Reader

        public UTF32Reader​(IOContext ctxt,
                           InputStream in,
                           byte[] buf,
                           int ptr,
                           int len,
                           boolean isBigEndian)
    • Method Detail

      • read

        public int read()
                 throws IOException
        Although this method is implemented by the base class, AND it should never be called by main code, let's still implement it bit more efficiently just in case
        Overrides:
        read in class Reader
        Throws:
        IOException
      • freeBuffers

        public final void freeBuffers()
        This method should be called along with (or instead of) normal close. After calling this method, no further reads should be tried. Method will try to recycle read buffers (if any).
      • reportBounds

        protected void reportBounds​(char[] cbuf,
                                    int start,
                                    int len)
                             throws IOException
        Throws:
        IOException