use of cn.hutool.core.exceptions.DependencyException in project hutool by looly.
the class ExcelSaxUtil method readFrom.
/**
* 从Excel的XML文档中读取内容,并使用{@link ContentHandler}处理
*
* @param xmlDocStream Excel的XML文档流
* @param handler 文档内容处理接口,实现此接口用于回调处理数据
* @throws DependencyException 依赖异常
* @throws POIException POI异常,包装了SAXException
* @throws IORuntimeException IO异常,如流关闭或异常等
* @since 5.1.4
*/
public static void readFrom(InputStream xmlDocStream, ContentHandler handler) throws DependencyException, POIException, IORuntimeException {
XMLReader xmlReader;
try {
// xmlReader = XMLReaderFactory.createXMLReader();
// noinspection deprecation
xmlReader = SAXHelper.newXMLReader();
} catch (SAXException | ParserConfigurationException e) {
if (e.getMessage().contains("org.apache.xerces.parsers.SAXParser")) {
throw new DependencyException(e, "You need to add 'xerces:xercesImpl' to your project and version >= 2.11.0");
} else {
throw new POIException(e);
}
}
xmlReader.setContentHandler(handler);
try {
xmlReader.parse(new InputSource(xmlDocStream));
} catch (IOException e) {
throw new IORuntimeException(e);
} catch (SAXException e) {
throw new POIException(e);
}
}
Aggregations