关闭JAX-RS StreamingOutput的OutputStream [英] Closing JAX-RS StreamingOutput's 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
是传递给的
。这很好,因为它的javadoc非常清楚这个 OutputStream
MessageBodyWriter 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.
这篇关于关闭JAX-RS StreamingOutput的OutputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!