关闭StreamSource

时间:2014-06-27 16:39:54

标签: java xslt java-ws

我的Web服务上出现了太多的打开文件错误,只是想确保没有其他任何我必须关闭的内容。我在close()outWriter)上添加了StringWriter,但JavaDoc说这没有效果。 getCachedExtractSoapBodyXslt()获取javax.xml.transform.Transformer个对象。

String payload;
StreamResult result=null;
StringWriter outWriter=null;
try {
    // Programmatically extract the SOAP Body from message
    outWriter = new StringWriter();
    result = new StreamResult(outWriter);
    Source src = new StreamSource(new java.io.StringReader(doc));
    getCachedExtractSoapBodyXslt().transform(src, result);
    StringBuffer sb = outWriter.getBuffer();
    payload = sb.toString();
} catch (TransformerException e) {
    throw new ComponentException("Unable to extract SOAP Body");
}
finally {
    LOG.debug("Closing XSLT transformer output stream");
    try {
        outWriter.close();
    }
    catch (IOException e) {
        LOG.error("Failed to close stream for SOAP message");
    }
}

1 个答案:

答案 0 :(得分:1)

我必须将其移动到它自己的变量并关闭它

new java.io.StringReader(doc)