有人能发布一个在Jersey中如何将StreamingOutput
设置为Response
对象实体的示例吗?
我一直没有找到这方面的示例。
有人能发布一个在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();
}