Top Description Fields Constructors Methods
com.fasterxml.aalto.in

public Class Utf32Reader

extends Reader
Class Inheritance
Imports
java.io.*, com.fasterxml.aalto.util.XmlConsts

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
mByteCount

Total read byte count; used for error reporting purposes

protected int
mCharCount

Total read character count; used for error reporting purposes

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

pack-priv char[]
private static final char
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public
Utf32Reader(ReaderConfig cfg, 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.
public final void
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 Woodstox 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.
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)

Inherited from java.io.Reader:
markmarkSupportednullReaderreadreadreadyresetskiptransferTo

Field Detail

mBigEndianback to summary
protected final boolean mBigEndian
mBufferback to summary
protected byte[] mBuffer
mByteCountback to summary
protected int mByteCount

Total read byte count; used for error reporting purposes

mCharCountback to summary
protected int mCharCount

Total read character count; used for error reporting purposes

mConfigback to summary
protected final ReaderConfig mConfig
mInback to summary
protected InputStream mIn
mLengthback to summary
protected int mLength
mPtrback to summary
protected int mPtr
mSurrogateback to summary
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.

mTmpBufback to summary
pack-priv char[] mTmpBuf
NULL_CHARback to summary
private static final char NULL_CHAR

Constructor Detail

Utf32Readerback to summary
public Utf32Reader(ReaderConfig cfg, 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
public final void freeBuffers()
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 Woodstox 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
protected 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
protected void reportStrangeStream() throws IOException
reportUnexpectedEOFback to summary
private void reportUnexpectedEOF(int gotBytes, int needed) throws IOException