Class UTF32Reader
java.lang.Object
java.io.Reader
tools.jackson.core.io.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 TypeFieldDescriptionprivate final booleanWhether underlyingInputStream(if any) should be closed when thisReaderis closed or not.protected final booleanprotected byte[]protected intTotal read byte count; used for error reporting purposesprotected intTotal read character count; used for error reporting purposesprotected final IOContextprotected InputStreamprotected intprotected final booleanprotected 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.protected char[]protected static final intJSON 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)protected static final char -
Constructor Summary
ConstructorsConstructorDescriptionUTF32Reader(IOContext ctxt, InputStream in, boolean autoClose, byte[] buf, int ptr, int len, boolean isBigEndian) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private voidThis method should be called along with (or instead of) normal close.private booleanloadMore(int available) intread()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 caseintread(char[] cbuf, int start, int len) private voidreportBounds(char[] cbuf, int start, int len) private voidreportInvalid(int value, int offset, String msg) private 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
-
LAST_VALID_UNICODE_CHAR
protected static final int LAST_VALID_UNICODE_CHARJSON 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:
-
NC
protected static final char NC- See Also:
-
_context
-
_in
-
_autoClose
private final boolean _autoCloseWhether underlyingInputStream(if any) should be closed when thisReaderis closed or not. -
_buffer
protected byte[] _buffer -
_ptr
protected int _ptr -
_length
protected int _length -
_bigEndian
protected final boolean _bigEndian -
_surrogate
protected char _surrogateAlthough 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. -
_charCount
protected int _charCountTotal read character count; used for error reporting purposes -
_byteCount
protected int _byteCountTotal read byte count; used for error reporting purposes -
_managedBuffers
protected final boolean _managedBuffers -
_tmpBuf
protected char[] _tmpBuf
-
-
Constructor Details
-
UTF32Reader
public UTF32Reader(IOContext ctxt, InputStream in, boolean autoClose, 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 main code, let's still implement it bit more efficiently just in case- Overrides:
readin classReader- Throws:
IOException
-
read
- Specified by:
readin classReader- Throws:
IOException
-
reportUnexpectedEOF
- Throws:
IOException
-
reportInvalid
- 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
private 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
- Throws:
IOException
-
reportStrangeStream
- Throws:
IOException
-