Package com.fasterxml.aalto.in
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 boolean
protected byte[]
protected int
Total read byte count; used for error reporting purposesprotected int
Total read character count; used for error reporting purposesprotected final ReaderConfig
protected InputStream
protected int
protected int
protected char
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.(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 TypeMethodDescriptionvoid
close()
final void
private boolean
loadMore
(int available) 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 caseint
read
(char[] cbuf, int start, int len) protected void
reportBounds
(char[] cbuf, int start, int len) private void
reportInvalid
(int value, int offset, String msg) protected void
private void
reportUnexpectedEOF
(int gotBytes, int needed) Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in 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:
read
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in 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
-