development

Jersey에서 StreamingOutput을 응답 엔터티로 사용하는 예

big-blog 2020. 10. 24. 11:09
반응형

Jersey에서 StreamingOutput을 응답 엔터티로 사용하는 예


누군가 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();
}

참고 URL : https://stackoverflow.com/questions/12012724/example-of-using-streamingoutput-as-response-entity-in-jersey

반응형