有人可以在Jersey中发布一个示例,说明如何将StreamingOutput
设置为Response
对象中的实体吗?
我无法找到这样的例子。
答案 0 :(得分:116)
看看这是否有帮助:
@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();
}