Top Description Fields Constructors Methods
com.ctc.wstx.io

public final Class UTF8Reader

extends BaseReader
Class Inheritance
Imports
java.io.*, com.ctc.wstx.api.ReaderConfig, com.ctc.wstx.cfg.XmlConsts

Optimized Reader that reads UTF-8 encoded content from an input stream. In addition to doing (hopefully) optimal conversion, it can also take array of "pre-read" (leftover) bytes; this is necessary when preliminary stream/reader is trying to figure out XML encoding.

Field Summary

Modifier and TypeField and Description
pack-priv int
mByteCount

Total read byte count; used for error reporting purposes

pack-priv int
mCharCount

Total read character count; used for error reporting purposes

pack-priv char
pack-priv boolean
Inherited from com.ctc.wstx.io.BaseReader:
CHAR_DELCONVERT_LSEP_TOCONVERT_NEL_TOmByteBuffermByteBufferEndmBytePtrmConfigmTmpBufNULL_BYTENULL_CHAR

Constructor Summary

AccessConstructor and Description
public
UTF8Reader(ReaderConfig cfg, InputStream in, byte[] buf, int ptr, int len, boolean recycleBuffer)

Method Summary

Modifier and TypeMethod and Description
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(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
reportInvalid(int value, int offset, String msg)

private void
reportInvalidInitial(int mask, int offset)

private void
reportInvalidOther(int mask, int offset)

private void
reportUnexpectedEOF(int gotBytes, int needed)

public void
setXmlCompliancy(int xmlVersion)

Implements abstract com.ctc.wstx.io.BaseReader.setXmlCompliancy.

Method that can be called to indicate the xml conformance used when reading content using this reader.

Inherited from com.ctc.wstx.io.BaseReader:
canModifyBufferclosefreeBuffersgetStreamreadreadBytesreadBytesAtreportBoundsreportInvalidXml11reportStrangeStream

Field Detail

mByteCountback to summary
pack-priv int mByteCount

Total read byte count; used for error reporting purposes

mCharCountback to summary
pack-priv int mCharCount

Total read character count; used for error reporting purposes

mSurrogateback to summary
pack-priv char mSurrogate
mXml11back to summary
pack-priv boolean mXml11

Constructor Detail

UTF8Readerback to summary
public UTF8Reader(ReaderConfig cfg, InputStream in, byte[] buf, int ptr, int len, boolean recycleBuffer)

Method Detail

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(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
@SuppressWarnings:cast
@Override
Exceptions
IOException:
If an I/O error occurs
reportInvalidback to summary
private void reportInvalid(int value, int offset, String msg) throws IOException
reportInvalidInitialback to summary
private void reportInvalidInitial(int mask, int offset) throws IOException
reportInvalidOtherback to summary
private void reportInvalidOther(int mask, int offset) throws IOException
reportUnexpectedEOFback to summary
private void reportUnexpectedEOF(int gotBytes, int needed) throws IOException
setXmlCompliancyback to summary
public void setXmlCompliancy(int xmlVersion)

Implements abstract com.ctc.wstx.io.BaseReader.setXmlCompliancy.

Doc from com.ctc.wstx.io.BaseReader.setXmlCompliancy.

Method that can be called to indicate the xml conformance used when reading content using this reader. Some of the character validity checks need to be done at reader level, and sometimes they depend on xml level (for example, xml 1.1 has new linefeeds and both more and less restricted characters).

Annotations
@Override