Class Utf32Reader
java.lang.Object
java.io.Reader
com.fasterxml.aalto.in.Utf32Reader
- All Implemented Interfaces:
Closeable, AutoCloseable, Readable
Since JDK does not come with UTF-32/UCS-4, let's implement a simple
decoder to use.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected byte[]protected intTotal read byte count; used for error reporting purposesprotected intTotal read character count; used for error reporting purposesprotected final ReaderConfigprotected InputStreamprotected intprotected intprotected charAlthough 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.(package private) char[]private static final char -
Constructor Summary
ConstructorsConstructorDescriptionUtf32Reader(ReaderConfig cfg, InputStream in, byte[] buf, int ptr, int len, boolean isBigEndian) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final voidprivate booleanloadMore(int available) intread()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 caseintread(char[] cbuf, int start, int len) protected voidreportBounds(char[] cbuf, int start, int len) private voidreportInvalid(int value, int offset, String msg) protected voidprivate voidreportUnexpectedEOF(int gotBytes, int needed) Methods inherited from class Reader
mark, markSupported, nullReader, of, read, read, readAllAsString, readAllLines, ready, reset, skip, transferTo
-
Field Details
-
NULL_CHAR
private static final char NULL_CHAR- See Also:
-
mConfig
-
mIn
-
mBuffer
protected byte[] mBuffer -
mPtr
protected int mPtr -
mLength
protected int mLength -
mBigEndian
protected final boolean mBigEndian -
mSurrogate
protected char mSurrogateAlthough 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 mCharCountTotal read character count; used for error reporting purposes -
mByteCount
protected int mByteCountTotal 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
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
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- Overrides:
readin classReader- Throws:
IOException
-
read
- Specified by:
readin classReader- Throws:
IOException
-
loadMore
- 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
- Throws:
IOException
-
reportInvalid
- Throws:
IOException
-
reportBounds
- Throws:
IOException
-
reportStrangeStream
- Throws:
IOException
-