title: How to return image as stream from JAX-RS?
body: <p>I'm trying to return an image in a JAX-RS web service.  I was able to get this successfully working by returning <code>FileInputStream</code> but I'd prefer to avoid creating a <code>File</code> for each request.</p>
  
  <p>I am using Apache CXF and Jackson (all the other resource methods produce application/json).</p>
  
  <p>Code looks like this:</p>
  
  <pre><code>@GET
  @Produces("image/png")
  public Response getQrCode(@QueryParam("qrtext") String qrtext) {
  
      ByteArrayOutputStream out = QRCode.from(qrtext).to(ImageType.PNG).stream();
  
      return Response.ok(out).build();
  }
  </code></pre>
  
  <p>Unfortunately, this produces the dreaded:</p>
  
  <blockquote>
    <p>org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor:376 - No message
    body writer has been found for response class ByteArrayOutputStream.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/5736973/dynamically-create-image-from-jax-rs-servlet">Here's</a> a link to a similar post but it doesn't mention the "No message body writer" issue I'm running into.</p>
  
  <p>I'd appreciate any ideas of how to deal with this issue.  Thanks!</p>