public FictionBook(File file) throws ParserConfigurationException, IOException, SAXException, OutOfMemoryError {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream inputStream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new FileReader(file));
String encoding = "utf-8";
try {
String line = br.readLine();
encoding = line.substring(line.indexOf("encoding=\"") + 10, line.indexOf("\"?>"));
} catch (Exception e) {
e.printStackTrace();
}
Document doc = db.parse(new InputSource(new InputStreamReader(inputStream, encoding)));
initXmlns(doc);
description = new Description(doc);
NodeList bodyNodes = doc.getElementsByTagName("body");
for (int item = 0; item < bodyNodes.getLength(); item++) {
bodies.add(new Body(bodyNodes.item(item)));
}
NodeList binary = doc.getElementsByTagName("binary");
for (int item = 0; item < binary.getLength(); item++) {
Binary binary1 = new Binary(binary.item(item));
binaries.put(binary1.getId().replace("#", ""), binary1);
}
}
FictionBook.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:fb2parser
作者:
评论列表
文章目录