Package com.fasterxml.aalto.in
Class Utf32Reader
- java.lang.Object
-
- java.io.Reader
-
- com.fasterxml.aalto.in.Utf32Reader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class Utf32Reader extends java.io.ReaderSince 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 booleanmBigEndianprotected byte[]mBufferprotected intmByteCountTotal read byte count; used for error reporting purposesprotected intmCharCountTotal read character count; used for error reporting purposesprotected ReaderConfigmConfigprotected java.io.InputStreammInprotected intmLengthprotected intmPtrprotected charmSurrogateAlthough 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[]mTmpBufprivate static charNULL_CHAR
-
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 voidclose()voidfreeBuffers()private 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, java.lang.String msg)protected voidreportStrangeStream()private voidreportUnexpectedEOF(int gotBytes, int needed)
-
-
-
Field Detail
-
NULL_CHAR
private static final char NULL_CHAR
- See Also:
- Constant Field Values
-
mConfig
protected final ReaderConfig mConfig
-
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
-
mTmpBuf
char[] mTmpBuf
-
-
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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOExceptionAlthough 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 classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int start, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
loadMore
private boolean loadMore(int available) throws java.io.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:
java.io.IOException
-
freeBuffers
public final void freeBuffers()
-
reportUnexpectedEOF
private void reportUnexpectedEOF(int gotBytes, int needed) throws java.io.IOException- Throws:
java.io.IOException
-
reportInvalid
private void reportInvalid(int value, int offset, java.lang.String msg) throws java.io.IOException- Throws:
java.io.IOException
-
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
-
-