private static WstxInputSource sourceFromURL(WstxInputSource parent, ReaderConfig cfg, String refName, int xmlVersion, URL url, String pubId) throws IOException, XMLStreamException { /* And then create the input source. Note that by default URL's * own input stream creation creates buffered reader -- for us * that's useless and wasteful (adds one unnecessary level of * caching, halving the speed due to copy operations needed), so * let's avoid it. */ InputStream in = URLUtil.inputStreamFromURL(url); SystemId sysId = SystemId.construct(url); StreamBootstrapper bs = StreamBootstrapper.getInstance(pubId, sysId, in); Reader r = bs.bootstrapInput(cfg, false, xmlVersion); return InputSourceFactory.constructEntitySource (cfg, parent, refName, bs, pubId, sysId, xmlVersion, r); }
/** * Factory method used when the underlying data provider is an * actual stream. */ public static StreamBootstrapper getInstance(String pubId, SystemId sysId, InputStream in) { return new StreamBootstrapper(pubId, sysId, in); }
/** * @return First character that does not match expected, if any; * CHAR_NULL if match succeeded */ protected int checkKeyword(String exp) throws IOException, WstxException { if (mBytesPerChar != 1) { if (mBytesPerChar == -1) { return checkTranslatedKeyword(exp); } return checkMbKeyword(exp); } return checkSbKeyword(exp); }
protected int getNextAfterWs(boolean reqWs) throws IOException, WstxException { int count; if (mBytesPerChar == 1) { // single byte count = skipSbWs(); } else { if (mBytesPerChar == -1) { // translated count = skipTranslatedWs(); } else { // multi byte count = skipMbWs(); } } if (reqWs && count == 0) { reportUnexpectedChar(getNext(), ERR_XMLDECL_EXP_SPACE); } // inlined getNext() if (mBytesPerChar != 1) { if (mBytesPerChar == -1) { // translated return nextTranslated(); } return nextMultiByte(); } byte b = (mInputPtr < mInputEnd) ? mByteBuffer[mInputPtr++] : nextByte(); return (b & 0xFF); }
if (ensureLoaded(6)) { if (mByteBuffer[mInputPtr] == '<' && mByteBuffer[mInputPtr+1] == '?' if (ensureLoaded(6)) { int start = mInputPtr; // if we have to 'unread' chars if (nextTranslated() == '<' && nextTranslated() == '?' && nextTranslated() == 'x' && nextTranslated() == 'm' && nextTranslated() == 'l' && nextTranslated() <= CHAR_SPACE) { return true; if (ensureLoaded (6 * mBytesPerChar)) { int start = mInputPtr; // if we have to 'unread' chars if (nextMultiByte() == '<' && nextMultiByte() == '?' && nextMultiByte() == 'x' && nextMultiByte() == 'm' && nextMultiByte() == 'l' && nextMultiByte() <= CHAR_SPACE) { return true;
resolveStreamEncoding(); if (hasXmlDecl()) { readXmlDecl(mainDoc, xmlVersion); if (mFoundEncoding != null) { normEnc = verifyXmlEncoding(mFoundEncoding); reportXmlProblem("Missing encoding declaration: underlying encoding looks like an EBCDIC variant, but no xml encoding declaration found");
if (ensureLoaded(4)) { bomblock: do { // BOM/auto-detection block break bomblock; case 0x0000FFFE: // UCS-4, in-order... reportWeirdUCS4("2143"); break bomblock; case 0x0FEFF0000: // UCS-4, in-order... reportWeirdUCS4("3412"); break bomblock; break bomblock; case 0x00003c00: // UCS-4, in-order... reportWeirdUCS4("2143"); break bomblock; case 0x003c0000: // UCS-4, in-order... reportWeirdUCS4("3412"); break bomblock; case 0x003c003f: // UTF-16, BE
private XMLStreamReader parse(InputStream is, String systemIdStr, boolean restricted) throws IOException, XMLStreamException { if (!quietmode) { LOG.debug("parsing input stream " + is); } if (is == null) { return null; } SystemId systemId = SystemId.construct(systemIdStr); ReaderConfig readerConfig = XML_INPUT_FACTORY.createPrivateConfig(); if (restricted) { readerConfig.setProperty(XMLInputFactory.SUPPORT_DTD, false); } return XML_INPUT_FACTORY.createSR(readerConfig, systemId, StreamBootstrapper.getInstance(null, systemId, is), false, true); }
protected void loadMore() throws IOException, WstxException { /* Need to make sure offsets are properly updated for error * reporting purposes, and do this now while previous amounts * are still known. */ /* Note: at this point these are all in bytes, not chars (for multibyte * encodings) */ mInputProcessed += mInputEnd; mInputRowStart -= mInputEnd; mInputPtr = 0; mInputEnd = (mIn == null) ? -1 : mIn.read(mByteBuffer, 0, mByteBuffer.length); if (mInputEnd < 1) { throw new WstxEOFException(ParsingErrorMsgs.SUFFIX_IN_XML_DECL, getLocation()); } }
protected int getNextAfterWs(boolean reqWs) throws IOException, WstxException { int count; if (mBytesPerChar == 1) { // single byte count = skipSbWs(); } else { if (mBytesPerChar == -1) { // translated count = skipTranslatedWs(); } else { // multi byte count = skipMbWs(); } } if (reqWs && count == 0) { reportUnexpectedChar(getNext(), ERR_XMLDECL_EXP_SPACE); } // inlined getNext() if (mBytesPerChar != 1) { if (mBytesPerChar == -1) { // translated return nextTranslated(); } return nextMultiByte(); } byte b = (mInputPtr < mInputEnd) ? mByteBuffer[mInputPtr++] : nextByte(); return (b & 0xFF); }
resolveStreamEncoding(); if (hasXmlDecl()) { readXmlDecl(mainDoc, xmlVersion); if (mFoundEncoding != null) { normEnc = verifyXmlEncoding(mFoundEncoding); reportXmlProblem("Missing encoding declaration: underlying encoding looks like an EBCDIC variant, but no xml encoding declaration found");
if (ensureLoaded(6)) { if (mByteBuffer[mInputPtr] == '<' && mByteBuffer[mInputPtr+1] == '?' if (ensureLoaded(6)) { int start = mInputPtr; // if we have to 'unread' chars if (nextTranslated() == '<' && nextTranslated() == '?' && nextTranslated() == 'x' && nextTranslated() == 'm' && nextTranslated() == 'l' && nextTranslated() <= CHAR_SPACE) { return true; if (ensureLoaded (6 * mBytesPerChar)) { int start = mInputPtr; // if we have to 'unread' chars if (nextMultiByte() == '<' && nextMultiByte() == '?' && nextMultiByte() == 'x' && nextMultiByte() == 'm' && nextMultiByte() == 'l' && nextMultiByte() <= CHAR_SPACE) { return true;
if (ensureLoaded(4)) { bomblock: do { // BOM/auto-detection block break bomblock; case 0x0000FFFE: // UCS-4, in-order... reportWeirdUCS4("2143"); break bomblock; case 0x0FEFF0000: // UCS-4, in-order... reportWeirdUCS4("3412"); break bomblock; break bomblock; case 0x00003c00: // UCS-4, in-order... reportWeirdUCS4("2143"); break bomblock; case 0x003c0000: // UCS-4, in-order... reportWeirdUCS4("3412"); break bomblock; case 0x003c003f: // UTF-16, BE
private XMLStreamReader2 createSR(ReaderConfig cfg, SystemId systemId, InputStream in, boolean forER, boolean autoCloseInput) throws XMLStreamException { return doCreateSR(cfg, systemId, StreamBootstrapper.getInstance(null, systemId, in), forER, autoCloseInput); }
private void reportMissingBOM(String enc) throws WstxException { throw new WstxException("Missing BOM for encoding '"+enc+"'; can not be omitted", getLocation()); } }
protected int getNextAfterWs(boolean reqWs) throws IOException, WstxException { int count; if (mBytesPerChar == 1) { // single byte count = skipSbWs(); } else { if (mBytesPerChar == -1) { // translated count = skipTranslatedWs(); } else { // multi byte count = skipMbWs(); } } if (reqWs && count == 0) { reportUnexpectedChar(getNext(), ERR_XMLDECL_EXP_SPACE); } // inlined getNext() if (mBytesPerChar != 1) { if (mBytesPerChar == -1) { // translated return nextTranslated(); } return nextMultiByte(); } byte b = (mInputPtr < mInputLen) ? mByteBuffer[mInputPtr++] : nextByte(); return (b & 0xFF); }
resolveStreamEncoding(); if (hasXmlDecl()) { readXmlDecl(mainDoc, xmlVersion); if (mFoundEncoding != null) { normEnc = verifyXmlEncoding(mFoundEncoding); reportXmlProblem("Missing encoding declaration: underlying encoding looks like an EBCDIC variant, but no xml encoding declaration found");
private static WstxInputSource sourceFromIS(WstxInputSource parent, ReaderConfig cfg, String refName, int xmlVersion, InputStream is, String pubId, String sysId) throws IOException, XMLStreamException { StreamBootstrapper bs = StreamBootstrapper.getInstance(pubId, SystemId.construct(sysId), is); Reader r = bs.bootstrapInput(cfg, false, xmlVersion); URL ctxt = parent.getSource(); // If we got a real sys id, we do know the source... if (sysId != null && sysId.length() > 0) { ctxt = URLUtil.urlFromSystemId(sysId, ctxt); } return InputSourceFactory.constructEntitySource (cfg, parent, refName, bs, pubId, SystemId.construct(sysId, ctxt), xmlVersion, r); }
/** * @return First character that does not match expected, if any; * CHAR_NULL if match succeeded */ protected int checkKeyword(String exp) throws IOException, WstxException { if (mBytesPerChar != 1) { if (mBytesPerChar == -1) { return checkTranslatedKeyword(exp); } return checkMbKeyword(exp); } return checkSbKeyword(exp); }
if (ensureLoaded(6)) { if (mByteBuffer[mInputPtr] == '<' && mByteBuffer[mInputPtr+1] == '?' if (ensureLoaded(6)) { int start = mInputPtr; // if we have to 'unread' chars if (nextTranslated() == '<' && nextTranslated() == '?' && nextTranslated() == 'x' && nextTranslated() == 'm' && nextTranslated() == 'l' && nextTranslated() <= CHAR_SPACE) { return true; if (ensureLoaded (6 * mBytesPerChar)) { int start = mInputPtr; // if we have to 'unread' chars if (nextMultiByte() == '<' && nextMultiByte() == '?' && nextMultiByte() == 'x' && nextMultiByte() == 'm' && nextMultiByte() == 'l' && nextMultiByte() <= CHAR_SPACE) { return true;