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

public final Class Utf8Scanner

extends StreamScanner
Class Inheritance
Imports
java.io.*, javax.xml.stream.XMLStreamException, com.fasterxml.aalto.impl.ErrorConsts, com.fasterxml.aalto.util.DataUtil, .XmlCharTypes, .XmlChars

Scanner for tokenizing XML content from a byte stream encoding using UTF-8 encoding, or something suitably close it for decoding purposes (including ISO-Latin1 and US-ASCII).

Field Summary

Inherited from com.fasterxml.aalto.in.StreamScanner:
_charTypes_in_inputBuffer_quadBuffer_symbols

Constructor Summary

AccessConstructor and Description
public
Utf8Scanner(ReaderConfig cfg, InputStream in, byte[] buffer, int ptr, int last)

Method Summary

Modifier and TypeMethod and Description
private final int
collectValue(int attrPtr, byte quoteByte, PName attrName)

This method implements the tight loop for parsing attribute values.

public int
decodeCharForError(byte b)

Implements abstract com.fasterxml.aalto.in.ByteBasedScanner.decodeCharForError.

Method called called to decode a full UTF-8 characters, given its first byte.
private final int

Returns:

Either decoded character (if positive int); or negated value of a high-order char (one that needs surrogate pair)
decodeMultiByteChar
(int c, int ptr)

private final int
decodeUtf8_2(int c)

private final int
decodeUtf8_3(int c1)

private final int
private final int

Returns:

Character value minus 0x10000; this so that caller can readily expand it to actual surrogates
decodeUtf8_4
(int c)

protected final void
protected final void
protected final void
protected final void
protected final void
finishCoalescedText()

Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been read in text buffer.

protected final void
protected final void
finishDTD(boolean copyContents)

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishDTD.

When this method gets called we know that we have an internal subset, and that the opening '[' has already been read.
protected final void
protected final void
finishSpace()

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishSpace.

Note

this method is only called in cases where it is known that only space chars are legal.

protected final void
finishToken()

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishToken.

This method is called to ensure that the current token/event has been completely parsed, such that we have all the data needed to return it (textual content, PI data, comment text etc)
protected final int

Returns:

0 if a general parsed entity encountered; integer value of a (valid) XML content character otherwise
handleEntityInText
(boolean
True, if reference is from attribute value; false if from normal text content
inAttr
)

Implements abstract com.fasterxml.aalto.in.StreamScanner.handleEntityInText.

Method called when an ampersand is encounter in text segment.
private void
handleNsDeclaration(PName name, byte quoteByte)

Method called from the main START_ELEMENT handling loop, to parse namespace URI values.

protected int
handleStartElement(byte b)

Implements abstract com.fasterxml.aalto.in.StreamScanner.handleStartElement.

Parsing of start element requires parsing of the element name (and attribute names), and is thus encoding-specific.
protected String
parsePublicId(byte quoteChar)

Implements abstract com.fasterxml.aalto.in.StreamScanner.parsePublicId.

Parsing of public ids is bit more complicated than that of system ids, since white space is to be coalesced.
protected String
protected void
reportInvalidOther(int mask, int ptr)

protected final void
protected final boolean
protected final boolean

Returns:

True if we encountered an unexpandable entity
skipCoalescedText
()

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipCoalescedText.

Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been skipped.
protected final void
protected final void
protected final void
private final void
skipUtf8_2(int c)

private final void
skipUtf8_3(int c)

private final void
skipUtf8_4(int c)

private final void
Inherited from com.fasterxml.aalto.in.StreamScanner:
_closeSource_nextEntity_releaseBuffersaddPNamecheckInTreeIndentationcheckPrologIndentationhandleCharEntityhandleEndElementloadAndRetainloadMoreloadOneloadOnenextBytenextBytenextFromProlognextFromTreeparsePNameparsePNameLongparsePNameMediumparsePNameSlowskipInternalWs

Constructor Detail

Utf8Scannerback to summary
public Utf8Scanner(ReaderConfig cfg, InputStream in, byte[] buffer, int ptr, int last)

Method Detail

collectValueback to summary
private final int collectValue(int attrPtr, byte quoteByte, PName attrName) throws XMLStreamException

This method implements the tight loop for parsing attribute values. It's off-lined from the main start element method to simplify main method, which makes code more maintainable and possibly easier for JIT/HotSpot to optimize.

decodeCharForErrorback to summary
public int decodeCharForError(byte b) throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.ByteBasedScanner.decodeCharForError.

Method called called to decode a full UTF-8 characters, given its first byte.

Note

does not do any validity checks, since this is only to be used for informational purposes (often when an error has already been encountered)

Annotations
@Override
decodeMultiByteCharback to summary
private final int decodeMultiByteChar(int c, int ptr) throws XMLStreamException
Returns:int

Either decoded character (if positive int); or negated value of a high-order char (one that needs surrogate pair)

decodeUtf8_2back to summary
private final int decodeUtf8_2(int c) throws XMLStreamException
decodeUtf8_3back to summary
private final int decodeUtf8_3(int c1) throws XMLStreamException
decodeUtf8_3fastback to summary
private final int decodeUtf8_3fast(int c1) throws XMLStreamException
decodeUtf8_4back to summary
private final int decodeUtf8_4(int c) throws XMLStreamException
Returns:int

Character value minus 0x10000; this so that caller can readily expand it to actual surrogates

finishCDataback to summary
protected final void finishCData() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishCData.

Annotations
@Override
finishCharactersback to summary
protected final void finishCharacters() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishCharacters.

Annotations
@Override
finishCoalescedCDataback to summary
protected final void finishCoalescedCData() throws XMLStreamException
finishCoalescedCharactersback to summary
protected final void finishCoalescedCharacters() throws XMLStreamException
finishCoalescedTextback to summary
protected final void finishCoalescedText() throws XMLStreamException

Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been read in text buffer. Method has to see if the following event would be textual as well, and if so, read it (and any other following textual segments).

finishCommentback to summary
protected final void finishComment() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishComment.

Annotations
@Override
finishDTDback to summary
protected final void finishDTD(boolean copyContents) throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishDTD.

When this method gets called we know that we have an internal subset, and that the opening '[' has already been read.

Annotations
@Override
finishPIback to summary
protected final void finishPI() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishPI.

Annotations
@Override
finishSpaceback to summary
protected final void finishSpace() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishSpace.

Note

this method is only called in cases where it is known that only space chars are legal. Thus, encountering a non-space is an error (WFC or VC). However, an end-of-input is ok.

Annotations
@Override
finishTokenback to summary
protected final void finishToken() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.finishToken.

Doc from com.fasterxml.aalto.in.XmlScanner.finishToken.

This method is called to ensure that the current token/event has been completely parsed, such that we have all the data needed to return it (textual content, PI data, comment text etc)

Annotations
@Override
handleEntityInTextback to summary
protected final int handleEntityInText(boolean inAttr) throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.StreamScanner.handleEntityInText.

Method called when an ampersand is encounter in text segment. Method needs to determine whether it is a pre-defined or character entity (in which case it will be expanded into a single char or surrogate pair), or a general entity (in which case it will most likely be returned as ENTITY_REFERENCE event)

Parameters
inAttr:boolean

True, if reference is from attribute value; false if from normal text content

Returns:int

0 if a general parsed entity encountered; integer value of a (valid) XML content character otherwise

Annotations
@Override
handleNsDeclarationback to summary
private void handleNsDeclaration(PName name, byte quoteByte) throws XMLStreamException

Method called from the main START_ELEMENT handling loop, to parse namespace URI values.

handleStartElementback to summary
protected int handleStartElement(byte b) throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.StreamScanner.handleStartElement.

Doc from com.fasterxml.aalto.in.StreamScanner.handleStartElement.

Parsing of start element requires parsing of the element name (and attribute names), and is thus encoding-specific.

Annotations
@Override
parsePublicIdback to summary
protected String parsePublicId(byte quoteChar) throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.StreamScanner.parsePublicId.

Parsing of public ids is bit more complicated than that of system ids, since white space is to be coalesced.

Annotations
@Override
parseSystemIdback to summary
protected String parseSystemId(byte quoteChar) throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.StreamScanner.parseSystemId.

Annotations
@Override
reportInvalidOtherback to summary
protected void reportInvalidOther(int mask, int ptr) throws XMLStreamException
skipCDataback to summary
protected final void skipCData() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipCData.

Annotations
@Override
skipCharactersback to summary
protected final boolean skipCharacters() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipCharacters.

Returns:boolean

Doc from com.fasterxml.aalto.in.XmlScanner.skipCharacters.

True, if an unexpanded entity was encountered (and is now pending)

Annotations
@Override
skipCoalescedTextback to summary
protected final boolean skipCoalescedText() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipCoalescedText.

Method that gets called after a primary text segment (of type CHARACTERS or CDATA, not applicable to SPACE) has been skipped. Method has to see if the following event would be textual as well, and if so, skip it (and any other following textual segments).

Returns:boolean

True if we encountered an unexpandable entity

Annotations
@Override
skipCommentback to summary
protected final void skipComment() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipComment.

Annotations
@Override
skipPIback to summary
protected final void skipPI() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipPI.

Annotations
@Override
skipSpaceback to summary
protected final void skipSpace() throws XMLStreamException

Implements abstract com.fasterxml.aalto.in.XmlScanner.skipSpace.

Annotations
@Override
skipUtf8_2back to summary
private final void skipUtf8_2(int c) throws XMLStreamException
skipUtf8_3back to summary
private final void skipUtf8_3(int c) throws XMLStreamException
skipUtf8_4back to summary
private final void skipUtf8_4(int c) throws XMLStreamException
skipUtf8_4Slowback to summary
private final void skipUtf8_4Slow(int c) throws XMLStreamException