Package com.ctc.wstx.io
Class StreamBootstrapper
- java.lang.Object
-
- com.ctc.wstx.io.InputBootstrapper
-
- com.ctc.wstx.io.StreamBootstrapper
-
public final class StreamBootstrapper extends InputBootstrapper
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
Fields Modifier and Type Field Description (package private) booleanmBigEndianprivate byte[]mByteBuffer(package private) booleanmByteSizeFound(package private) intmBytesPerCharFor most encodings, number of physical characters needed for decoding xml declaration characters (which for variable length encodings like UTF-8 will be 1).(package private) booleanmEBCDICSpecial case for 1-byte encodings: EBCDIC is problematic as it's not 7-bit ascii compatible.(package private) booleanmHadBOM(package private) java.io.InputStreammInUnderlying InputStream to use for reading content.(package private) static intMIN_BUF_SIZELet'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.(package private) java.lang.StringmInputEncodingprivate intmInputEndprivate intmInputPtrprivate booleanmRecycleBufferWhether byte buffer is recyclable or not(package private) int[]mSingleByteTranslationFor single-byte non-ascii-compatible encodings (ok ok, really just EBCDIC), we'll have to use a lookup table.-
Fields inherited from class com.ctc.wstx.io.InputBootstrapper
BYTE_CR, BYTE_LF, BYTE_NULL, CHAR_CR, CHAR_LF, CHAR_NEL, CHAR_NULL, CHAR_SPACE, ERR_XMLDECL_END_MARKER, ERR_XMLDECL_EXP_ATTRVAL, ERR_XMLDECL_EXP_EQ, ERR_XMLDECL_EXP_SPACE, ERR_XMLDECL_KW_ENCODING, ERR_XMLDECL_KW_STANDALONE, ERR_XMLDECL_KW_VERSION, mDeclaredXmlVersion, mFoundEncoding, mInputProcessed, mInputRow, mInputRowStart, mKeywordBuffer, mPublicId, mStandalone, mSystemId, mXml11Handling
-
-
Constructor Summary
Constructors Modifier Constructor Description privateStreamBootstrapper(java.lang.String pubId, SystemId sysId, byte[] data, int start, int end)privateStreamBootstrapper(java.lang.String pubId, SystemId sysId, java.io.InputStream in)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.ReaderbootstrapInput(ReaderConfig cfg, boolean mainDoc, int xmlVersion)protected intcheckKeyword(java.lang.String exp)protected intcheckMbKeyword(java.lang.String expected)protected intcheckSbKeyword(java.lang.String expected)protected intcheckTranslatedKeyword(java.lang.String expected)protected booleanensureLoaded(int minimum)intgetInputColumn()java.lang.StringgetInputEncoding()Since this class only gets used when encoding is not explicitly passed, need use the encoding that was auto-detected...intgetInputTotal()static StreamBootstrappergetInstance(java.lang.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.static StreamBootstrappergetInstance(java.lang.String pubId, SystemId sysId, java.io.InputStream in)Factory method used when the underlying data provider is an actual stream.protected javax.xml.stream.LocationgetLocation()protected intgetNext()protected intgetNextAfterWs(boolean reqWs)protected booleanhasXmlDecl()protected voidloadMore()protected bytenextByte()protected intnextMultiByte()protected intnextTranslated()protected voidpushback()protected intreadQuotedValue(char[] outputBuffer, int quoteChar)private voidreportWeirdUCS4(java.lang.String type)protected voidresolveStreamEncoding()Method called to try to figure out physical encoding the underlying input stream uses.protected voidskipMbLF(int lf)protected intskipMbWs()protected voidskipSbLF(byte lfByte)protected intskipSbWs()protected voidskipTranslatedLF(int lf)protected intskipTranslatedWs()private voidverifyEncoding(java.lang.String id, int bpc)private voidverifyEncoding(java.lang.String id, int bpc, boolean bigEndian)protected java.lang.StringverifyXmlEncoding(java.lang.String enc)-
Methods inherited from class com.ctc.wstx.io.InputBootstrapper
declaredXml11, getDeclaredEncoding, getDeclaredVersion, getInputRow, getPublicId, getStandalone, getSystemId, initFrom, readXmlDecl, reportNull, reportUnexpectedChar, reportXmlProblem
-
-
-
-
Field Detail
-
MIN_BUF_SIZE
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 ("- See Also:
- Constant Field Values
-
mIn
final java.io.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.
-
mByteBuffer
private byte[] mByteBuffer
-
mRecycleBuffer
private final boolean mRecycleBuffer
Whether byte buffer is recyclable or not
-
mInputPtr
private int mInputPtr
-
mInputEnd
private int mInputEnd
-
mBigEndian
boolean mBigEndian
-
mHadBOM
boolean mHadBOM
-
mByteSizeFound
boolean mByteSizeFound
-
mBytesPerChar
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.
-
mEBCDIC
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.
-
mInputEncoding
java.lang.String mInputEncoding
-
mSingleByteTranslation
int[] mSingleByteTranslation
For single-byte non-ascii-compatible encodings (ok ok, really just EBCDIC), we'll have to use a lookup table.
-
Constructor Detail
-
StreamBootstrapper
private StreamBootstrapper(java.lang.String pubId, SystemId sysId, java.io.InputStream in)
-
StreamBootstrapper
private StreamBootstrapper(java.lang.String pubId, SystemId sysId, byte[] data, int start, int end)- Parameters:
start- Pointer to the first valid byte in the bufferend- Pointer to the offset after last valid byte in the buffer
-
-
Method Detail
-
getInstance
public static StreamBootstrapper getInstance(java.lang.String pubId, SystemId sysId, java.io.InputStream in)
Factory method used when the underlying data provider is an actual stream.
-
getInstance
public static StreamBootstrapper getInstance(java.lang.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.
-
bootstrapInput
public java.io.Reader bootstrapInput(ReaderConfig cfg, boolean mainDoc, int xmlVersion) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Specified by:
bootstrapInputin classInputBootstrapperxmlVersion- 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.- Throws:
java.io.IOExceptionjavax.xml.stream.XMLStreamException
-
getInputEncoding
public java.lang.String getInputEncoding()
Since this class only gets used when encoding is not explicitly passed, need use the encoding that was auto-detected...- Specified by:
getInputEncodingin classInputBootstrapper- Returns:
- Input encoding in use, if it could be determined or was passed by the calling application
-
getInputTotal
public int getInputTotal()
- Specified by:
getInputTotalin classInputBootstrapper- Returns:
- Total number of characters read from bootstrapped input (stream, reader)
-
getInputColumn
public int getInputColumn()
- Specified by:
getInputColumnin classInputBootstrapper
-
resolveStreamEncoding
protected void resolveStreamEncoding() throws java.io.IOException, WstxExceptionMethod called to try to figure out physical encoding the underlying input stream uses.- Throws:
java.io.IOExceptionWstxException
-
verifyXmlEncoding
protected java.lang.String verifyXmlEncoding(java.lang.String enc) throws WstxException- Returns:
- Normalized encoding name
- Throws:
WstxException
-
ensureLoaded
protected boolean ensureLoaded(int minimum) throws java.io.IOException- Throws:
java.io.IOException
-
loadMore
protected void loadMore() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
pushback
protected void pushback()
- Specified by:
pushbackin classInputBootstrapper
-
getNext
protected int getNext() throws java.io.IOException, WstxException- Specified by:
getNextin classInputBootstrapper- Throws:
java.io.IOExceptionWstxException
-
getNextAfterWs
protected int getNextAfterWs(boolean reqWs) throws java.io.IOException, WstxException- Specified by:
getNextAfterWsin classInputBootstrapper- Throws:
java.io.IOExceptionWstxException
-
checkKeyword
protected int checkKeyword(java.lang.String exp) throws java.io.IOException, WstxException- Specified by:
checkKeywordin classInputBootstrapper- Returns:
- First character that does not match expected, if any; CHAR_NULL if match succeeded
- Throws:
java.io.IOExceptionWstxException
-
readQuotedValue
protected int readQuotedValue(char[] outputBuffer, int quoteChar) throws java.io.IOException, WstxException- Specified by:
readQuotedValuein classInputBootstrapper- Throws:
java.io.IOExceptionWstxException
-
hasXmlDecl
protected boolean hasXmlDecl() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
getLocation
protected javax.xml.stream.Location getLocation()
- Specified by:
getLocationin classInputBootstrapper
-
nextByte
protected byte nextByte() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
skipSbWs
protected int skipSbWs() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
skipSbLF
protected void skipSbLF(byte lfByte) throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
checkSbKeyword
protected int checkSbKeyword(java.lang.String expected) throws java.io.IOException, WstxException- Returns:
- First character that does not match expected, if any; CHAR_NULL if match succeeded
- Throws:
java.io.IOExceptionWstxException
-
nextMultiByte
protected int nextMultiByte() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
nextTranslated
protected int nextTranslated() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
skipMbWs
protected int skipMbWs() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
skipTranslatedWs
protected int skipTranslatedWs() throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
skipMbLF
protected void skipMbLF(int lf) throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
skipTranslatedLF
protected void skipTranslatedLF(int lf) throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
checkMbKeyword
protected int checkMbKeyword(java.lang.String expected) throws java.io.IOException, WstxException- Returns:
- First character that does not match expected, if any; CHAR_NULL if match succeeded
- Throws:
java.io.IOExceptionWstxException
-
checkTranslatedKeyword
protected int checkTranslatedKeyword(java.lang.String expected) throws java.io.IOException, WstxException- Throws:
java.io.IOExceptionWstxException
-
verifyEncoding
private void verifyEncoding(java.lang.String id, int bpc) throws WstxException- Throws:
WstxException
-
verifyEncoding
private void verifyEncoding(java.lang.String id, int bpc, boolean bigEndian) throws WstxException- Throws:
WstxException
-
reportWeirdUCS4
private void reportWeirdUCS4(java.lang.String type) throws java.io.IOException- Throws:
java.io.IOException
-
-
-