How to return image as stream from JAX-RS?

Just use StreamingOutput wrapper. For some reason it is unknown, but it is GREAT for providing, well, streaming output. :-)


I think you need to provide an InputStream containing the image in the Response.ok(out) not an OutputStream. (Your JAX-RS framework would read the bytes from the InputStream and put them onto the response, it wouldn't be able to do anything generically with an OutputStream)

(I know you're on CXF, but Jersey's doc: http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e324 and by the JAX-RS spec, the framework must provide a MessageBodyWriter for InputStream.)

Edit: You apparently know about InputStreams being required, d'oh... Do you have control over the QRCode class?

Short term, you might be able to do:

return Response.ok(out.toByteArray()).build();