【发布时间】:2011-02-10 03:47:41
【问题描述】:
请看看我做了什么
private InputSource getContent(String fName) throws SAXException, IOException, ServiceException {
// Some code here
if(currentNodeRef != null)
{
ContentReader reader = contentService.getReader(currentNodeRef,ContentModel.PROP_CONTENT);
InputStream inputStream = null;
try
{
inputStream = new BufferedInputStream(reader.getContentInputStream(),16384);
return new InputSource(inputStream);
}
finally
{
if(inputStream!=null)
try
{
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return new InputSource();
}
在我的 parseDocument 方法中,我调用了上述方法。
parseDocRoot(getContent(fName),path);
在 parseDocRoot 中
public void parseDocRoot (InputSource ins, String path) throws SAXException, IOException,
ParserConfigurationException, ServiceException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
return new InputSource(new ByteArrayInputStream(new byte[0]));
}
});
Document doc = builder.parse(ins);
NodeList list = doc.getChildNodes();
parseDocument(list,path);
}
我得到一个错误说 Stream Not closed 并且在调试上面的代码时我发现错误就行了
Document doc = builder.parse(ins);
请帮我找到解决办法。
【问题讨论】:
-
(第一个)答案很可能是正确的,但通常您最好提供完整的堆栈跟踪而不是错误描述;它使事情变得更容易并避免混淆。