Top Description Fields Constructors Methods
com.fasterxml.jackson.core.io

public Class UTF32Reader

extends Reader
Class Inheritance
Imports
java.io.*

Since JDK does not come with UTF-32/UCS-4, let's implement a simple decoder to use.

Field Summary

Modifier and TypeField and Description
protected final boolean
protected byte[]
protected int
_byteCount

Total read byte count; used for error reporting purposes

protected int
_charCount

Total read character count; used for error reporting purposes

protected final IOContext
protected InputStream
protected int
protected final boolean
protected int
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.

protected 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)

protected static final char
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public
UTF32Reader(IOContext ctxt, InputStream in, byte[] buf, int ptr, int len, boolean isBigEndian)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

private void
freeBuffers()

This method should be called along with (or instead of) normal close.

private boolean

Returns:

True, if enough bytes were read to allow decoding of at least one full character; false if EOF was encountered instead.
loadMore
(int
Number of "unused" bytes in the input buffer
available
)

public int
read()

Overrides java.io.Reader.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

public int
read(char[]
Destination buffer
cbuf
,
int
Offset at which to start storing characters
start
,
int
Maximum number of characters to read
len
)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

private void
reportBounds(char[] cbuf, int start, int len)

private void
reportInvalid(int value, int offset, String msg)

private void
private void
reportUnexpectedEOF(int gotBytes, int needed)

Inherited from java.io.Reader:
markmarkSupportednullReaderreadreadreadyresetskiptransferTo

Field Detail

_bigEndianback to summary
protected final boolean _bigEndian
_bufferback to summary
protected byte[] _buffer
_byteCountback to summary
protected int _byteCount

Total read byte count; used for error reporting purposes

_charCountback to summary
protected int _charCount

Total read character count; used for error reporting purposes

_contextback to summary
protected final IOContext _context
_inback to summary
protected InputStream _in
_lengthback to summary
protected int _length
_managedBuffersback to summary
protected final boolean _managedBuffers
_ptrback to summary
protected int _ptr
_surrogateback to summary
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.

_tmpBufback to summary
protected char[] _tmpBuf
LAST_VALID_UNICODE_CHARback to summary
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)

NCback to summary
protected static final char NC

Constructor Detail

UTF32Readerback to summary
public UTF32Reader(IOContext ctxt, InputStream in, byte[] buf, int ptr, int len, boolean isBigEndian)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
freeBuffersback to summary
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).

loadMoreback to summary
private boolean loadMore(int available) throws IOException
Parameters
available:int

Number of "unused" bytes in the input buffer

Returns:boolean

True, if enough bytes were read to allow decoding of at least one full character; false if EOF was encountered instead.

readback to summary
public int read() throws IOException

Overrides java.io.Reader.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

Returns:int

Doc from java.io.Reader.read.

The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Reader.read.

If an I/O error occurs

readback to summary
public int read(char[] cbuf, int start, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Parameters
cbuf:char[]

Destination buffer

start:int

Offset at which to start storing characters

len:int

Maximum number of characters to read

Returns:int

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
reportBoundsback to summary
private void reportBounds(char[] cbuf, int start, int len) throws IOException
reportInvalidback to summary
private void reportInvalid(int value, int offset, String msg) throws IOException
reportStrangeStreamback to summary
private void reportStrangeStream() throws IOException
reportUnexpectedEOFback to summary
private void reportUnexpectedEOF(int gotBytes, int needed) throws IOException