Class Utf32Reader

java.lang.Object
java.io.Reader
com.fasterxml.aalto.in.Utf32Reader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

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

    • NULL_CHAR

      private static final char NULL_CHAR
      See Also:
    • mConfig

      protected final ReaderConfig mConfig
    • mIn

      protected 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
    • mTmpBuf

      char[] mTmpBuf
  • Constructor Details

    • Utf32Reader

      public Utf32Reader(ReaderConfig cfg, InputStream in, byte[] buf, int ptr, int len, boolean isBigEndian)
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      Throws:
      IOException
    • read

      public int read() throws 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 Reader
      Throws:
      IOException
    • read

      public int read(char[] cbuf, int start, int len) throws IOException
      Specified by:
      read in class Reader
      Throws:
      IOException
    • loadMore

      private boolean loadMore(int available) throws 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:
      IOException
    • freeBuffers

      public final void freeBuffers()
    • reportUnexpectedEOF

      private void reportUnexpectedEOF(int gotBytes, int needed) throws IOException
      Throws:
      IOException
    • reportInvalid

      private void reportInvalid(int value, int offset, String msg) throws IOException
      Throws:
      IOException
    • reportBounds

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

      protected void reportStrangeStream() throws IOException
      Throws:
      IOException