关闭StreamSource [英] Closing StreamSource

查看:134
本文介绍了关闭StreamSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web服务上遇到太多打开文件错误,只是想确保没有其他需要关闭的内容.我在outWriter(StringWriter)上添加了close(),但是JavaDoc表示这没有效果. getCachedExtractSoapBodyXslt()获取javax.xml.transform.Transformer对象.

I was getting a too many open files error on my web service and just wanted to make sure that there's nothing else that I have to close. I added a close() on outWriter (StringWriter), but the JavaDoc said that this has no effect. getCachedExtractSoapBodyXslt() gets the javax.xml.transform.Transformer object.

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");
    }
}

推荐答案

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

I had to move this to it's own variable and to close it

new java.io.StringReader(doc)

这篇关于关闭StreamSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆