Example of using StreamingOutput as Response entity in Jersey

后端 未结 1 1322
春和景丽
春和景丽 2020-11-27 11:18

Can someone post an example of how in Jersey to set StreamingOutput as an entity in a Response object?

I haven\'t been able to find an exam

相关标签:
1条回答
  • 2020-11-27 12:12

    See if this helps:

    @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();
    }
    
    0 讨论(0)
提交回复
热议问题