0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JAX-RSのStreamingOutputをロジックに依存させない

Last updated at Posted at 2023-05-19

大きいデータをレスポンスに流すときに便利なStreamingOutputだが、適当に使うとロジックに入り込んで後々取り扱いずらくなる。

class SomeLogic {
  public Consumer<OutputStream> execute() {
    byte[] hogehoge;
    return out -> out.write(hogehoge);
  }
}
SomeLogic logic = new SomeLogic();
Consumer<OutputStream> output = logic.execute();
StreamingOutput streamingOutput = output::accept;
return Response.ok().entitiy(streamingOutput).build();

のように実装することにした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?