关闭JAX-RS StreamingOutput的OutputStream [英] Closing JAX-RS StreamingOutput's OutputStream

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

问题描述

实施类是否应关闭 StreamingOutput OutputStream

Should the StreamingOutput's OutputStream be closed by the implementing class?

java-doc不提供任何建议。我想它只是委托给底层的 ServletOutputStream 这意味着它不应该被关闭,但我的猜测可能是错误的:)而且javadoc引用了 MessageBodyWriter 接口,其中明确表示不得关闭输出流。

The java-doc does not give any recommendations. I guess it just delegates to the underlying ServletOutputStream which means it should not be closed, but my guess might be wrong :) Also the javadoc makes a reference to the MessageBodyWriter interface where it's explicitly said that the output stream must not be closed.

https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/StreamingOutput.html

推荐答案

由于无法找到明确的答案,我看了一下球衣的来源是参考实施。在Jersey中, StreamingOutput MessageBodyWriter 处理,只需调用 streamingOutput.write(os) [1]其中 os 是传递给 OutputStream MessageBodyWriter 。这很好,因为它的javadoc非常清楚这个 OutputStream 必须才能关闭。

Being unable to find a definitive answer I took a look at jersey's source being the reference implementation. In Jersey the StreamingOutput is processed by a MessageBodyWriter by simply calling streamingOutput.write(os) [1] where os is the OutputStream passed to the MessageBodyWriter. That's good because its javadoc is quite clear that this OutputStream must not be closed.

总结一下: OutputStream 传递给 StreamingOutput 不得关闭。

To summarize: The OutputStream passed to the StreamingOutput must not be closed.

[1] https://github.com/jersey/jersey/blob/master/core-common /src/main/java/org/glassfish/jersey/message/internal/StreamingOutputProvider.java

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

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