Closing JAX-RS StreamingOutput's OutputStream

前端 未结 1 578
野的像风
野的像风 2021-02-05 12:46

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

The java-doc does not give any recommendation

相关标签:
1条回答
  • 2021-02-05 13:20

    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.

    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

    0 讨论(0)
提交回复
热议问题