Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of using StreamingOutput as Response entity in Jersey

Tags:

jersey

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 example of this.

like image 533
David Loy Avatar asked Aug 17 '12 20:08

David Loy


1 Answers

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(); } 
like image 123
condit Avatar answered Oct 09 '22 11:10

condit