77

誰かがジャージーでオブジェクトStreamingOutputのエンティティとして設定する方法の例を投稿できますか?Response

私はこの例を見つけることができませんでした。

4

1 に答える 1

127

これが役立つかどうかを確認してください:

@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();
}
于 2012-08-17T20:39:28.003 に答える