Example of using StreamingOutput as a response object in Jersey

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

I could not find an example of this.

+63
jersey
Aug 17 '12 at 20:26
source share
1 answer

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(); } 
+107
Aug 17 2018-12-12T00:
source share



All Articles