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