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

public final Class StreamBootstrapper

extends InputBootstrapper
Class Inheritance
Imports
java.io.*, javax.xml.stream.Location, .XMLStreamException, com.ctc.wstx.api.ReaderConfig, com.ctc.wstx.cfg.ParsingErrorMsgs, .XmlConsts, com.ctc.wstx.exc.*

Input bootstrap class used with streams, when encoding is not known (when encoding is specified by application, a reader is constructed, and then reader-based bootstrapper is used).

Encoding used for an entity (including main document entity) is determined using algorithms suggested in XML 1.0#3 spec, appendix F

Field Summary

Modifier and TypeField and Description
pack-priv boolean
private byte[]
pack-priv boolean
pack-priv int
mBytesPerChar

For most encodings, number of physical characters needed for decoding xml declaration characters (which for variable length encodings like UTF-8 will be 1).

pack-priv boolean
mEBCDIC

Special case for 1-byte encodings: EBCDIC is problematic as it's not 7-bit ascii compatible.

pack-priv boolean
pack-priv final InputStream
mIn

Underlying InputStream to use for reading content.

pack-priv static final int
MIN_BUF_SIZE

Let's size buffer at least big enough to contain the longest possible prefix of a document needed to positively identify it starts with the XML declaration.

pack-priv String
private int
private int
private final boolean
mRecycleBuffer

Whether byte buffer is recyclable or not

pack-priv int[]
mSingleByteTranslation

For single-byte non-ascii-compatible encodings (ok ok, really just EBCDIC), we'll have to use a lookup table.

Inherited from com.ctc.wstx.io.InputBootstrapper:
BYTE_CRBYTE_LFBYTE_NULLCHAR_CRCHAR_LFCHAR_NELCHAR_NULLCHAR_SPACEERR_XMLDECL_END_MARKERERR_XMLDECL_EXP_ATTRVALERR_XMLDECL_EXP_EQERR_XMLDECL_EXP_SPACEERR_XMLDECL_KW_ENCODINGERR_XMLDECL_KW_STANDALONEERR_XMLDECL_KW_VERSIONmDeclaredXmlVersionmFoundEncodingmInputProcessedmInputRowmInputRowStartmKeywordBuffermPublicIdmStandalonemSystemIdmXml11Handling

Constructor Summary

AccessConstructor and Description
private
private
StreamBootstrapper(String pubId, SystemId sysId, byte[] data, int
Pointer to the first valid byte in the buffer
start
,
int
Pointer to the offset after last valid byte in the buffer
end
)

Method Summary

Modifier and TypeMethod and Description
public Reader
bootstrapInput(ReaderConfig cfg, boolean mainDoc, int
Optional xml version identifier of the main parsed document (if not bootstrapping the main document). Currently only relevant for checking that XML 1.0 document does not include XML 1.1 external parsed entities. If null, no checks will be done; when bootstrapping parsing of the main document, null should be passed for this argument.
xmlVersion
)

Implements abstract com.ctc.wstx.io.InputBootstrapper.bootstrapInput.

protected int

Returns:

First character that does not match expected, if any; CHAR_NULL if match succeeded
checkKeyword
(String exp)

Implements abstract com.ctc.wstx.io.InputBootstrapper.checkKeyword.

protected int

Returns:

First character that does not match expected, if any; CHAR_NULL if match succeeded
checkMbKeyword
(String expected)

protected int

Returns:

First character that does not match expected, if any; CHAR_NULL if match succeeded
checkSbKeyword
(String expected)

protected int
protected boolean
ensureLoaded(int minimum)

public int
public String
getInputEncoding()

Implements abstract com.ctc.wstx.io.InputBootstrapper.getInputEncoding.

Since this class only gets used when encoding is not explicitly passed, need use the encoding that was auto-detected...

public int
public static StreamBootstrapper
getInstance(String pubId, SystemId sysId, InputStream in)

Factory method used when the underlying data provider is an actual stream.

public static StreamBootstrapper
getInstance(String pubId, SystemId sysId, byte[] data, int start, int end)

Factory method used when the underlying data provider is a pre-allocated block source, and no stream is used.

protected Location
protected int
protected int
protected boolean
protected void
protected byte
protected int
protected int
protected void
protected int
readQuotedValue(char[] outputBuffer, int quoteChar)

Implements abstract com.ctc.wstx.io.InputBootstrapper.readQuotedValue.

private void
protected void
resolveStreamEncoding()

Method called to try to figure out physical encoding the underlying input stream uses.

protected void
skipMbLF(int lf)

protected int
protected void
skipSbLF(byte lfByte)

protected int
protected void
protected int
private void
verifyEncoding(String id, int bpc)

private void
verifyEncoding(String id, int bpc, boolean bigEndian)

protected String

Returns:

Normalized encoding name
verifyXmlEncoding
(String enc)

Inherited from com.ctc.wstx.io.InputBootstrapper:
declaredXml11getDeclaredEncodinggetDeclaredVersiongetInputRowgetPublicIdgetStandalonegetSystemIdinitFromreadXmlDeclreportNullreportUnexpectedCharreportXmlProblem

Field Detail

mBigEndianback to summary
pack-priv boolean mBigEndian
mByteBufferback to summary
private byte[] mByteBuffer
mByteSizeFoundback to summary
pack-priv boolean mByteSizeFound
mBytesPerCharback to summary
pack-priv int mBytesPerChar

For most encodings, number of physical characters needed for decoding xml declaration characters (which for variable length encodings like UTF-8 will be 1). Exception is EBCDIC, which while a single-byte encoding, is denoted by -1 since it needs an additional translation lookup.

mEBCDICback to summary
pack-priv boolean mEBCDIC

Special case for 1-byte encodings: EBCDIC is problematic as it's not 7-bit ascii compatible. We can deal with it, still, but only with bit of extra state.

mHadBOMback to summary
pack-priv boolean mHadBOM
mInback to summary
pack-priv final InputStream mIn

Underlying InputStream to use for reading content. May be null if the actual data source is not stream-based but a block source.

MIN_BUF_SIZEback to summary
pack-priv static final int MIN_BUF_SIZE

Let's size buffer at least big enough to contain the longest possible prefix of a document needed to positively identify it starts with the XML declaration. That means having (optional) BOM, and then first 6 characters ("<?xml "), in whatever encoding. With 4-byte encodings (UCS-4), that comes to 28 bytes. And for good measure, let's pad that a bit as well....

mInputEncodingback to summary
pack-priv String mInputEncoding
mInputEndback to summary
private int mInputEnd
mInputPtrback to summary
private int mInputPtr
mRecycleBufferback to summary
private final boolean mRecycleBuffer

Whether byte buffer is recyclable or not

mSingleByteTranslationback to summary
pack-priv int[] mSingleByteTranslation

For single-byte non-ascii-compatible encodings (ok ok, really just EBCDIC), we'll have to use a lookup table.

Constructor Detail

StreamBootstrapperback to summary
private StreamBootstrapper(String pubId, SystemId sysId, InputStream in)
StreamBootstrapperback to summary
private StreamBootstrapper(String pubId, SystemId sysId, byte[] data, int start, int end)
Parameters
start:int

Pointer to the first valid byte in the buffer

end:int

Pointer to the offset after last valid byte in the buffer

Method Detail

bootstrapInputback to summary
public Reader bootstrapInput(ReaderConfig cfg, boolean mainDoc, int xmlVersion) throws IOException, XMLStreamException

Implements abstract com.ctc.wstx.io.InputBootstrapper.bootstrapInput.

Parameters
xmlVersion:int

Doc from com.ctc.wstx.io.InputBootstrapper.bootstrapInput.

Optional xml version identifier of the main parsed document (if not bootstrapping the main document). Currently only relevant for checking that XML 1.0 document does not include XML 1.1 external parsed entities. If null, no checks will be done; when bootstrapping parsing of the main document, null should be passed for this argument.

Annotations
@SuppressWarnings:resource
@Override
checkKeywordback to summary
protected int checkKeyword(String exp) throws IOException, WstxException

Implements abstract com.ctc.wstx.io.InputBootstrapper.checkKeyword.

Returns:int

First character that does not match expected, if any; CHAR_NULL if match succeeded

Annotations
@Override
checkMbKeywordback to summary
protected int checkMbKeyword(String expected) throws IOException, WstxException
Returns:int

First character that does not match expected, if any; CHAR_NULL if match succeeded

checkSbKeywordback to summary
protected int checkSbKeyword(String expected) throws IOException, WstxException
Returns:int

First character that does not match expected, if any; CHAR_NULL if match succeeded

checkTranslatedKeywordback to summary
protected int checkTranslatedKeyword(String expected) throws IOException, WstxException
ensureLoadedback to summary
protected boolean ensureLoaded(int minimum) throws IOException
getInputColumnback to summary
public int getInputColumn()

Implements abstract com.ctc.wstx.io.InputBootstrapper.getInputColumn.

Annotations
@Override
getInputEncodingback to summary
public String getInputEncoding()

Implements abstract com.ctc.wstx.io.InputBootstrapper.getInputEncoding.

Since this class only gets used when encoding is not explicitly passed, need use the encoding that was auto-detected...

Returns:String

Doc from com.ctc.wstx.io.InputBootstrapper.getInputEncoding.

Input encoding in use, if it could be determined or was passed by the calling application

Annotations
@Override
getInputTotalback to summary
public int getInputTotal()

Implements abstract com.ctc.wstx.io.InputBootstrapper.getInputTotal.

Returns:int

Doc from com.ctc.wstx.io.InputBootstrapper.getInputTotal.

Total number of characters read from bootstrapped input (stream, reader)

Annotations
@Override
getInstanceback to summary
public static StreamBootstrapper getInstance(String pubId, SystemId sysId, InputStream in)

Factory method used when the underlying data provider is an actual stream.

getInstanceback to summary
public static StreamBootstrapper getInstance(String pubId, SystemId sysId, byte[] data, int start, int end)

Factory method used when the underlying data provider is a pre-allocated block source, and no stream is used. Additionally the buffer passed is not owned by the bootstrapper or Reader that is created, so it is not to be recycled.

getLocationback to summary
protected Location getLocation()

Implements abstract com.ctc.wstx.io.InputBootstrapper.getLocation.

Annotations
@Override
getNextback to summary
protected int getNext() throws IOException, WstxException

Implements abstract com.ctc.wstx.io.InputBootstrapper.getNext.

Annotations
@Override
getNextAfterWsback to summary
protected int getNextAfterWs(boolean reqWs) throws IOException, WstxException

Implements abstract com.ctc.wstx.io.InputBootstrapper.getNextAfterWs.

Annotations
@Override
hasXmlDeclback to summary
protected boolean hasXmlDecl() throws IOException, WstxException
loadMoreback to summary
protected void loadMore() throws IOException, WstxException
nextByteback to summary
protected byte nextByte() throws IOException, WstxException
nextMultiByteback to summary
protected int nextMultiByte() throws IOException, WstxException
nextTranslatedback to summary
protected int nextTranslated() throws IOException, WstxException
pushbackback to summary
protected void pushback()

Implements abstract com.ctc.wstx.io.InputBootstrapper.pushback.

Annotations
@Override
readQuotedValueback to summary
protected int readQuotedValue(char[] outputBuffer, int quoteChar) throws IOException, WstxException

Implements abstract com.ctc.wstx.io.InputBootstrapper.readQuotedValue.

Annotations
@Override
reportWeirdUCS4back to summary
private void reportWeirdUCS4(String type) throws IOException
resolveStreamEncodingback to summary
protected void resolveStreamEncoding() throws IOException, WstxException

Method called to try to figure out physical encoding the underlying input stream uses.

skipMbLFback to summary
protected void skipMbLF(int lf) throws IOException, WstxException
skipMbWsback to summary
protected int skipMbWs() throws IOException, WstxException
skipSbLFback to summary
protected void skipSbLF(byte lfByte) throws IOException, WstxException
skipSbWsback to summary
protected int skipSbWs() throws IOException, WstxException
skipTranslatedLFback to summary
protected void skipTranslatedLF(int lf) throws IOException, WstxException
skipTranslatedWsback to summary
protected int skipTranslatedWs() throws IOException, WstxException
verifyEncodingback to summary
private void verifyEncoding(String id, int bpc) throws WstxException
verifyEncodingback to summary
private void verifyEncoding(String id, int bpc, boolean bigEndian) throws WstxException
verifyXmlEncodingback to summary
protected String verifyXmlEncoding(String enc) throws WstxException
Returns:String

Normalized encoding name