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

public final Class ReaderScanner

extends XmlScanner
Class Inheritance
Imports
java.io.*, javax.xml.stream.XMLStreamException, org.codehaus.stax2.XMLStreamLocation2, com.fasterxml.aalto.impl.ErrorConsts, .IoStreamException, .LocationImpl, com.fasterxml.aalto.util.DataUtil, .TextBuilder, .XmlCharTypes, .XmlChars, .XmlConsts

This is the concrete scanner implementation used when input comes as a java.io.Reader. In general using this scanner is quite a bit less optimal than that of java.io.InputStream based scanner. Nonetheless, it is included for completeness, since Stax interface allows passing Readers as input sources.

Field Summary

Modifier and TypeField and Description
protected Reader
_in

Underlying InputStream to use for reading content.

protected char[]
protected int
protected int
protected final CharBasedPNameTable
_symbols

For now, symbol table contains prefixed names.

protected int
mTmpChar

Storage location for a single character that can not be pushed back (for example, multi-byte char)

private static final XmlCharTypes
sCharTypes

Although java chars are basically UTF-16 in memory, the closest match for char types is Latin1.

Inherited from com.fasterxml.aalto.in.XmlScanner:
_attrCollector_attrCount_cfgCoalescing_cfgLazyParsing_config_currElem_currNsCount_currRow_currToken_defaultNs_depth_entityPending_isEmptyTag_lastNsContext_lastNsDecl_nameBuffer_nsBindingCache_nsBindingCount_nsBindings_nsBindMisses_pastBytesOrChars_publicId_rowStartOffset_startColumn_startRawOffset_startRow_systemId_textBuilder_tokenIncomplete_tokenName_xml11CDATA_STRINT_0INT_9INT_AINT_aINT_AMPINT_APOSINT_COLONINT_CRINT_EQINT_EXCLINT_FINT_fINT_GTINT_HYPHENINT_LBRACKETINT_LFINT_LTINT_NULLINT_QMARKINT_QUOTEINT_RBRACKETINT_SLASHINT_SPACEINT_TABINT_zMAX_UNICODE_CHARTOKEN_EOI

Constructor Summary

AccessConstructor and Description
public
ReaderScanner(ReaderConfig cfg, Reader r, char[] buffer, int ptr, int last)

public

Method Summary

Modifier and TypeMethod and Description
protected void
protected int
_nextEntity()

Helper method used to isolate things that need to be (re)set in cases where

protected void
protected final PName
addPName(char[] nameBuffer, int nameLen, int hash)

protected final int

Returns:

-1, if indentation was handled; offset in the output buffer, if not
checkInTreeIndentation
(char c)

Note

consequtive white space is only considered indentation, if the following token seems like a tag (start/end).

protected final int

Returns:

-1, if indentation was handled; offset in the output buffer, if not
checkPrologIndentation
(char c)

private char
checkSurrogate(char firstChar)

This method is called to verify that a surrogate pair found describes a legal surrogate pair (ie.

private int
checkSurrogateNameChar(char firstChar, char sec, int index)

private int
collectValue(int attrPtr, char quoteChar, PName attrName)

This method implements the tight loop for parsing attribute values.

private int
decodeSurrogate(char firstChar)

This method is similar to checkSurrogate, but returns the actual character code encoded by the surrogate pair.

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.

protected final void
protected final void
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)
public int
public XMLStreamLocation2
public long
public long
public long
public long
protected final int

Returns:

Code point for the entity that expands to a valid XML content character.
handleCharEntity
()

protected final int
private final int
protected final int
protected final int
handleEntityInText(boolean inAttr)

private void
handleNsDeclaration(PName name, char quoteChar)

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

protected final int
protected final int
handlePrologDeclStart(boolean isProlog)

protected final int
protected final boolean
loadAndRetain(int nrOfChars)

protected final boolean
protected final char
protected final char
loadOne(int type)

protected final void
markLF(int offset)

protected final void
private final void
public final int
public final int
protected PName
parsePName(char c)

protected String
parsePublicId(char quoteChar)

protected String
parseSystemId(char quoteChar)

private void
private void
protected final void
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 char

Returns:

First byte following skipped white space
skipInternalWs
(boolean reqd, String msg)

protected final void
protected final void
Inherited from com.fasterxml.aalto.in.XmlScanner:
bindNamebindNscheckImmutableBindingclosedecodeAttrBinaryValuedecodeAttrValuedecodeAttrValuesdecodeElementsfindAttrIndexfindOrCreateBindingfireSaxCharacterEventsfireSaxCommentEventfireSaxEndElementfireSaxPIEventfireSaxSpaceEventsfireSaxStartElementgetAttrCollectorgetAttrCountgetAttrLocalNamegetAttrNsURIgetAttrPrefixgetAttrPrefixedNamegetAttrQNamegetAttrTypegetAttrValuegetAttrValuegetConfiggetCurrentLineNrgetDepthgetDTDPublicIdgetDTDSystemIdgetEndLocationgetInputPublicIdgetInputSystemIdgetNamegetNamespacePrefixgetNamespaceURIgetNamespaceURIgetNamespaceURIgetNonTransientNamespaceContextgetNsCountgetPrefixgetPrefixesgetQNamegetStartLocationgetTextgetTextgetTextCharactersgetTextCharactersgetTextLengthhandleInvalidXmlCharhasEmptyStackisAttrSpecifiedisEmptyTagisTextWhitespaceloadMoreGuaranteedloadMoreGuaranteedreportDoubleHyphenInCommentsreportDuplicateNsDeclreportEntityOverflowreportEofInNamereportIllegalCDataEndreportIllegalNsDeclreportIllegalNsDeclreportInputProblemreportInvalidNameCharreportInvalidNsIndexreportInvalidXmlCharreportMissingPISpacereportMultipleColonsInNamereportPrologProblemreportPrologUnexpCharreportPrologUnexpElementreportTreeUnexpCharreportUnboundPrefixreportUnexpandedEntityInAttrreportUnexpectedEndTagresetForDecodingskipTokenthrowInvalidSpacethrowNullCharthrowUnexpectedCharverifyXmlChar

Field Detail

_inback to summary
protected Reader _in

Underlying InputStream to use for reading content.

_inputBufferback to summary
protected char[] _inputBuffer
_inputEndback to summary
protected int _inputEnd
_inputPtrback to summary
protected int _inputPtr
_symbolsback to summary
protected final CharBasedPNameTable _symbols

For now, symbol table contains prefixed names. In future it is possible that they may be split into prefixes and local names?

mTmpCharback to summary
protected int mTmpChar

Storage location for a single character that can not be pushed back (for example, multi-byte char)

sCharTypesback to summary
private static final XmlCharTypes sCharTypes

Although java chars are basically UTF-16 in memory, the closest match for char types is Latin1.

Constructor Detail

ReaderScannerback to summary
public ReaderScanner(ReaderConfig cfg, Reader r, char[] buffer, int ptr, int last)
ReaderScannerback to summary
public ReaderScanner(ReaderConfig cfg, Reader r)

Method Detail

_closeSourceback to summary
protected void _closeSource() throws IOException

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

Annotations
@Override
_nextEntityback to summary
protected int _nextEntity()

Helper method used to isolate things that need to be (re)set in cases where

_releaseBuffersback to summary
protected void _releaseBuffers()

Overrides com.fasterxml.aalto.in.XmlScanner._releaseBuffers.

Annotations
@Override
addPNameback to summary
protected final PName addPName(char[] nameBuffer, int nameLen, int hash) throws XMLStreamException
checkInTreeIndentationback to summary
protected final int checkInTreeIndentation(char c) throws XMLStreamException

Note

consequtive white space is only considered indentation, if the following token seems like a tag (start/end). This so that if a CDATA section follows, it can be coalesced in coalescing mode. Although we could check if coalescing mode is enabled, this should seldom have significant effect either way, so it removes one possible source of problems in coalescing mode.

Returns:int

-1, if indentation was handled; offset in the output buffer, if not

checkPrologIndentationback to summary
protected final int checkPrologIndentation(char c) throws XMLStreamException
Returns:int

-1, if indentation was handled; offset in the output buffer, if not

checkSurrogateback to summary
private char checkSurrogate(char firstChar) throws XMLStreamException

This method is called to verify that a surrogate pair found describes a legal surrogate pair (ie. expands to a legal XML char)

checkSurrogateNameCharback to summary
private int checkSurrogateNameChar(char firstChar, char sec, int index) throws XMLStreamException
collectValueback to summary
private int collectValue(int attrPtr, char quoteChar, 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.

decodeSurrogateback to summary
private int decodeSurrogate(char firstChar) throws XMLStreamException

This method is similar to checkSurrogate, but returns the actual character code encoded by the surrogate pair. This is needed if further validation rules (such as name charactert checks) are to be done.

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.

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.

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
getCurrentColumnNrback to summary
public int getCurrentColumnNr()

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

Annotations
@Override
getCurrentLocationback to summary
public XMLStreamLocation2 getCurrentLocation()

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

Returns:XMLStreamLocation2

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

Current input location

Annotations
@Override
getEndingByteOffsetback to summary
public long getEndingByteOffset() throws XMLStreamException

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

Annotations
@Override
getEndingCharOffsetback to summary
public long getEndingCharOffset() throws XMLStreamException

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

Annotations
@Override
getStartingByteOffsetback to summary
public long getStartingByteOffset()

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

Annotations
@Override
getStartingCharOffsetback to summary
public long getStartingCharOffset()

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

Annotations
@Override
handleCharEntityback to summary
protected final int handleCharEntity() throws XMLStreamException
Returns:int

Code point for the entity that expands to a valid XML content character.

handleCommentOrCdataStartback to summary
protected final int handleCommentOrCdataStart() throws XMLStreamException
handleDtdStartback to summary
private final int handleDtdStart() throws XMLStreamException
handleEndElementback to summary
protected final int handleEndElement() throws XMLStreamException
handleEntityInTextback to summary
protected final int handleEntityInText(boolean inAttr) throws XMLStreamException
handleNsDeclarationback to summary
private void handleNsDeclaration(PName name, char quoteChar) throws XMLStreamException

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

handlePIStartback to summary
protected final int handlePIStart() throws XMLStreamException
handlePrologDeclStartback to summary
protected final int handlePrologDeclStart(boolean isProlog) throws XMLStreamException
handleStartElementback to summary
protected final int handleStartElement(char c) throws XMLStreamException
loadAndRetainback to summary
protected final boolean loadAndRetain(int nrOfChars) throws XMLStreamException
loadMoreback to summary
protected final boolean loadMore() throws XMLStreamException

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

Annotations
@Override
loadOneback to summary
protected final char loadOne() throws XMLStreamException
loadOneback to summary
protected final char loadOne(int type) throws XMLStreamException
markLFback to summary
protected final void markLF(int offset)
markLFback to summary
protected final void markLF()
matchAsciiKeywordback to summary
private final void matchAsciiKeyword(String keyw) throws XMLStreamException
nextFromPrologback to summary
public final int nextFromProlog(boolean isProlog) throws XMLStreamException

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

Annotations
@Override
nextFromTreeback to summary
public final int nextFromTree() throws XMLStreamException

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

Annotations
@Override
parsePNameback to summary
protected PName parsePName(char c) throws XMLStreamException
parsePublicIdback to summary
protected String parsePublicId(char quoteChar) throws XMLStreamException
parseSystemIdback to summary
protected String parseSystemId(char quoteChar) throws XMLStreamException
reportInvalidFirstSurrogateback to summary
private void reportInvalidFirstSurrogate(char ch) throws XMLStreamException
reportInvalidSecondSurrogateback to summary
private void reportInvalidSecondSurrogate(char ch) throws XMLStreamException
setStartLocationback to summary
protected final void setStartLocation()
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
skipInternalWsback to summary
protected char skipInternalWs(boolean reqd, String msg) throws XMLStreamException
Returns:char

First byte following skipped white space

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