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

public abstract Class StreamScanner

extends ByteBasedScanner
Class Inheritance
Known Direct Subclasses
com.fasterxml.aalto.in.Utf8Scanner
Imports
java.io.*, javax.xml.stream.XMLStreamException, com.fasterxml.aalto.impl.ErrorConsts, .IoStreamException, com.fasterxml.aalto.util.DataUtil, .TextBuilder, .XmlCharTypes

Base class for various byte stream based scanners (generally one for each type of encoding supported).

Field Summary

Modifier and TypeField and Description
protected final XmlCharTypes
_charTypes

This is a simple container object that is used to access the decoding tables for characters.

protected InputStream
_in

Underlying InputStream to use for reading content.

protected byte[]
protected int[]
_quadBuffer

This buffer is used for name parsing.

protected final ByteBasedPNameTable
_symbols

For now, symbol table contains prefixed names.

Inherited from com.fasterxml.aalto.in.ByteBasedScanner:
_inputEnd_inputPtr_tmpCharBYTE_aBYTE_ABYTE_AMPBYTE_APOSBYTE_CBYTE_CRBYTE_DBYTE_EQBYTE_EXCLBYTE_gBYTE_GTBYTE_HASHBYTE_HYPHENBYTE_lBYTE_LBRACKETBYTE_LFBYTE_LTBYTE_mBYTE_NULLBYTE_oBYTE_pBYTE_PBYTE_qBYTE_QMARKBYTE_QUOTBYTE_RBRACKETBYTE_sBYTE_SBYTE_SEMICOLONBYTE_SLASHBYTE_SPACEBYTE_tBYTE_TBYTE_TABBYTE_uBYTE_x

Constructor Summary

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

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(int hash, int[] quads, int qlen, int lastQuadBytes)

protected final int

Returns:

-1, if indentation was handled; offset in the output buffer, if not
checkInTreeIndentation
(int 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
(int c)

private final PName
findPName(int
Word with 1 to 4 bytes that make up PName
onlyQuad
,
int
Number of actual bytes contained in onlyQuad; 0 to 3.
lastByteCount
)

Method called to process a sequence of bytes that is likely to be a PName.

private final PName
findPName(int
First 1 to 4 bytes of the PName
firstQuad
,
int
Word with last 1 to 4 bytes of the PName
secondQuad
,
int
Number of bytes contained in secondQuad; 0 to 3.
lastByteCount
)

Method called to process a sequence of bytes that is likely to be a PName.

private final PName
findPName(int
Word with last 0 to 3 bytes of the PName; not included in the quad array
lastQuad
,
int[]
Array that contains all the quads, except for the last one, for names with more than 8 bytes (i.e. more than 2 quads)
quads
,
int
Number of quads in the array, except if less than 2 (in which case only firstQuad and lastQuad are used)
qlen
,
int
Number of bytes contained in lastQuad; 0 to 3.
lastByteCount
)

Method called to process a sequence of bytes that is likely to be a PName.

private final PName
findPName(int
Word with last 0 to 3 bytes of the PName; not included in the quad array
lastQuad
,
int
Number of bytes contained in lastQuad; 0 to 3.
lastByteCount
,
int
First 1 to 4 bytes of the PName (4 if length at least 4 bytes; less only if not).
firstQuad
,
int
Number of quads in the array, except if less than 2 (in which case only firstQuad and lastQuad are used)
qlen
,
int[]
Array that contains all the quads, except for the last one, for names with more than 8 bytes (i.e. more than 2 quads)
quads
)

Method called to process a sequence of bytes that is likely to be a PName.

protected final int

Returns:

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

private final int
private final int
protected final int
handleEndElement()

Note that this method is currently also shareable for all Ascii-based encodings, and at least between UTF-8 and ISO-Latin1.

private final int
protected abstract int
handleEntityInText(boolean inAttr)

private final int
private final int
handlePrologDeclStart(boolean isProlog)

protected abstract int
handleStartElement(byte b)

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

protected final boolean
loadAndRetain(int nrOfChars)

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

private final void
protected final byte
nextByte(int tt)

protected final byte
public final int
public final int
protected final PName
parsePName(byte b)

This method can (for now?) be shared between all Ascii-based encodings, since it only does coarse validity checking -- real checks are done in different method.

protected final PName
parsePNameLong(int q, int[] quads)

protected PName
parsePNameMedium(int i2, int q1)

protected final PName
protected abstract String
parsePublicId(byte quoteChar)

protected abstract String
parseSystemId(byte quoteChar)

protected byte

Returns:

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

Inherited from com.fasterxml.aalto.in.ByteBasedScanner:
addUTFPNamedecodeCharForErrorgetCurrentColumnNrgetCurrentLocationgetEndingByteOffsetgetEndingCharOffsetgetStartingByteOffsetgetStartingCharOffsetmarkLFmarkLFreportInvalidInitialreportInvalidOthersetStartLocation

Field Detail

_charTypesback to summary
protected final XmlCharTypes _charTypes

This is a simple container object that is used to access the decoding tables for characters. Indirection is needed since we actually support multiple utf-8 compatible encodings, not just utf-8 itself.

_inback to summary
protected InputStream _in

Underlying InputStream to use for reading content.

_inputBufferback to summary
protected byte[] _inputBuffer
_quadBufferback to summary
protected int[] _quadBuffer

This buffer is used for name parsing. Will be expanded if/as needed; 32 ints can hold names 128 ascii chars long.

_symbolsback to summary
protected final ByteBasedPNameTable _symbols

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

Constructor Detail

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

Method Detail

_closeSourceback to summary
protected void _closeSource() throws IOException

Implements abstract com.fasterxml.aalto.in.ByteBasedScanner._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(int hash, int[] quads, int qlen, int lastQuadBytes) throws XMLStreamException
checkInTreeIndentationback to summary
protected final int checkInTreeIndentation(int 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(int c) throws XMLStreamException
Returns:int

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

findPNameback to summary
private final PName findPName(int onlyQuad, int lastByteCount) throws XMLStreamException

Method called to process a sequence of bytes that is likely to be a PName. At this point we encountered an end marker, and may either hit a formerly seen well-formed PName; an as-of-yet unseen well-formed PName; or a non-well-formed sequence (containing one or more non-name chars without any valid end markers).

Parameters
onlyQuad:int

Word with 1 to 4 bytes that make up PName

lastByteCount:int

Number of actual bytes contained in onlyQuad; 0 to 3.

findPNameback to summary
private final PName findPName(int firstQuad, int secondQuad, int lastByteCount) throws XMLStreamException

Method called to process a sequence of bytes that is likely to be a PName. At this point we encountered an end marker, and may either hit a formerly seen well-formed PName; an as-of-yet unseen well-formed PName; or a non-well-formed sequence (containing one or more non-name chars without any valid end markers).

Parameters
firstQuad:int

First 1 to 4 bytes of the PName

secondQuad:int

Word with last 1 to 4 bytes of the PName

lastByteCount:int

Number of bytes contained in secondQuad; 0 to 3.

findPNameback to summary
private final PName findPName(int lastQuad, int[] quads, int qlen, int lastByteCount) throws XMLStreamException

Method called to process a sequence of bytes that is likely to be a PName. At this point we encountered an end marker, and may either hit a formerly seen well-formed PName; an as-of-yet unseen well-formed PName; or a non-well-formed sequence (containing one or more non-name chars without any valid end markers).

Parameters
lastQuad:int

Word with last 0 to 3 bytes of the PName; not included in the quad array

quads:int[]

Array that contains all the quads, except for the last one, for names with more than 8 bytes (i.e. more than 2 quads)

qlen:int

Number of quads in the array, except if less than 2 (in which case only firstQuad and lastQuad are used)

lastByteCount:int

Number of bytes contained in lastQuad; 0 to 3.

findPNameback to summary
private final PName findPName(int lastQuad, int lastByteCount, int firstQuad, int qlen, int[] quads) throws XMLStreamException

Method called to process a sequence of bytes that is likely to be a PName. At this point we encountered an end marker, and may either hit a formerly seen well-formed PName; an as-of-yet unseen well-formed PName; or a non-well-formed sequence (containing one or more non-name chars without any valid end markers).

Parameters
lastQuad:int

Word with last 0 to 3 bytes of the PName; not included in the quad array

lastByteCount:int

Number of bytes contained in lastQuad; 0 to 3.

firstQuad:int

First 1 to 4 bytes of the PName (4 if length at least 4 bytes; less only if not).

qlen:int

Number of quads in the array, except if less than 2 (in which case only firstQuad and lastQuad are used)

quads:int[]

Array that contains all the quads, except for the last one, for names with more than 8 bytes (i.e. more than 2 quads)

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
private final int handleCommentOrCdataStart() throws XMLStreamException
handleDtdStartback to summary
private final int handleDtdStart() throws XMLStreamException
handleEndElementback to summary
protected final int handleEndElement() throws XMLStreamException

Note that this method is currently also shareable for all Ascii-based encodings, and at least between UTF-8 and ISO-Latin1. The reason is that since we already know exact bytes that need to be matched, there's no danger of getting invalid encodings or such. So, for now, let's leave this method here in the base class.

handleEndElementSlowback to summary
private final int handleEndElementSlow(int size) throws XMLStreamException
handleEntityInTextback to summary
protected abstract int handleEntityInText(boolean inAttr) throws XMLStreamException
handlePIStartback to summary
private final int handlePIStart() throws XMLStreamException

<?M<?e<?t<?h<?o<?d<? <?c<?a<?l<?l<?e<?d<? <?a<?f<?t<?e<?r<? <?l<?e<?a<?d<?i<?n<?g<? <?'<?<??<?'<? <?h<?a<?s<? <?b<?e<?e<?n<? <?p<?a<?r<?s<?e<?d<?;<? <?n<?e<?e<?d<?s<? <?t<?o<? <?p<?a<?r<?s<?e<? <? <? <?t<?a<?r<?g<?e<?t<?.<?

handlePrologDeclStartback to summary
private final int handlePrologDeclStart(boolean isProlog) throws XMLStreamException
handleStartElementback to summary
protected abstract int handleStartElement(byte b) throws XMLStreamException

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

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 byte loadOne() throws XMLStreamException
loadOneback to summary
protected final byte loadOne(int type) throws XMLStreamException
matchAsciiKeywordback to summary
private final void matchAsciiKeyword(String keyw) throws XMLStreamException
nextByteback to summary
protected final byte nextByte(int tt) throws XMLStreamException
nextByteback to summary
protected final byte nextByte() 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 final PName parsePName(byte b) throws XMLStreamException

This method can (for now?) be shared between all Ascii-based encodings, since it only does coarse validity checking -- real checks are done in different method.

Some notes about assumption implementation makes:

  • Well-formed xml content can not end with a name: as such, end-of-input is an error and we can throw an exception
parsePNameLongback to summary
protected final PName parsePNameLong(int q, int[] quads) throws XMLStreamException
parsePNameMediumback to summary
protected PName parsePNameMedium(int i2, int q1) throws XMLStreamException
parsePNameSlowback to summary
protected final PName parsePNameSlow(byte b) throws XMLStreamException
parsePublicIdback to summary
protected abstract String parsePublicId(byte quoteChar) throws XMLStreamException
parseSystemIdback to summary
protected abstract String parseSystemId(byte quoteChar) throws XMLStreamException
skipInternalWsback to summary
protected byte skipInternalWs(boolean reqd, String msg) throws XMLStreamException
Returns:byte

First byte following skipped white space