private void setUpXMLParser(ReadableByteChannel channel, byte[] lookAhead) throws IOException {
try {
// We use Woodstox because the StAX implementation provided by OpenJDK reports
// character locations incorrectly. Note that Woodstox still currently reports *byte*
// locations incorrectly when parsing documents that contain multi-byte characters.
XMLInputFactory2 xmlInputFactory = (XMLInputFactory2) XMLInputFactory.newInstance();
this.parser = xmlInputFactory.createXMLStreamReader(
new SequenceInputStream(
new ByteArrayInputStream(lookAhead), Channels.newInputStream(channel)),
getCurrentSource().configuration.getCharset());
// Current offset should be the offset before reading the record element.
while (true) {
int event = parser.next();
if (event == XMLStreamConstants.START_ELEMENT) {
String localName = parser.getLocalName();
if (localName.equals(getCurrentSource().configuration.getRecordElement())) {
break;
}
}
}
} catch (FactoryConfigurationError | XMLStreamException e) {
throw new IOException(e);
}
}
XmlSource.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:beam
作者:
评论列表
文章目录