在Jersey中将StreamingOutput用作响应实体的示例 [英] Example of using StreamingOutput as Response entity in Jersey
本文介绍了在Jersey中将StreamingOutput用作响应实体的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以举一个例子说明在Jersey如何将StreamingOutput
设置为Response
对象中的实体吗?
Can someone post an example of how in Jersey to set StreamingOutput
as an entity in a Response
object?
我无法找到一个例子.
推荐答案
看看是否有帮助:
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response streamExample() {
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException,
WebApplicationException {
Writer writer = new BufferedWriter(new OutputStreamWriter(os));
writer.write("test");
writer.flush(); // <-- This is very important. Do not forget.
}
};
return Response.ok(stream).build();
}
这篇关于在Jersey中将StreamingOutput用作响应实体的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文