Package org.codehaus.jackson.io
Class UTF32Reader
- java.lang.Object
-
- java.io.Reader
-
- org.codehaus.jackson.io.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 boolean_bigEndianprotected byte[]_bufferprotected int_byteCountTotal read byte count; used for error reporting purposesprotected int_charCountTotal read character count; used for error reporting purposesprotected IOContext_contextprotected java.io.InputStream_inprotected int_lengthprotected boolean_managedBuffersprotected int_ptrprotected 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.protected char[]_tmpBufprotected static intLAST_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)protected static charNULL_BYTEprotected static charNULL_CHAR
-
Constructor Summary
Constructors Constructor Description UTF32Reader(IOContext ctxt, 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()This method should be called along with (or instead of) normal close.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)protected voidreportBounds(char[] cbuf, int start, int len)protected voidreportStrangeStream()
-
-
-
Field Detail
-
_bigEndian
protected final boolean _bigEndian
-
_surrogate
protected char _surrogate
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.
-
_charCount
protected int _charCount
Total read character count; used for error reporting purposes
-
_byteCount
protected int _byteCount
Total read byte count; used for error reporting purposes
-
_managedBuffers
protected final boolean _managedBuffers
-
LAST_VALID_UNICODE_CHAR
protected static final int LAST_VALID_UNICODE_CHAR
JSON 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:
- Constant Field Values
-
NULL_CHAR
protected static final char NULL_CHAR
- See Also:
- Constant Field Values
-
NULL_BYTE
protected static final char NULL_BYTE
- See Also:
- Constant Field Values
-
_context
protected final IOContext _context
-
_in
protected java.io.InputStream _in
-
_buffer
protected byte[] _buffer
-
_ptr
protected int _ptr
-
_length
protected int _length
-
_tmpBuf
protected char[] _tmpBuf
-
-
Constructor Detail
-
UTF32Reader
public UTF32Reader(IOContext ctxt, java.io.InputStream in, byte[] buf, int ptr, int len, boolean isBigEndian)
-
-
Method Detail
-
read
public int read(char[] cbuf, int start, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
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 main code, let's still implement it bit more efficiently just in case- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
freeBuffers
public final 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
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
-
-