title: Input and Output binary streams using JERSEY?
body: <p>I'm using Jersey to implement a RESTful API that is primarily retrieve and serve JSON encoded data. But I have some situations where I need to accomplish the following:</p>
  
  <ul>
  <li>Export downloadable documents, such as PDF, XLS, ZIP, or other binary files.</li>
  <li>Retrieve multipart data, such some JSON plus an uploaded XLS file</li>
  </ul>
  
  <p>I have a single-page JQuery-based web client that creates AJAX calls to this web service. At the moment, it doesn't do form submits, and uses GET and POST (with a JSON object). Should I utilize a form post to send data and an attached binary file, or can I create a multipart request with JSON plus binary file?</p>
  
  <p>My application's service layer currently creates a ByteArrayOutputStream when it generates a PDF file. What is the best way to output this stream to the client via Jersey? I've created a MessageBodyWriter, but I don't know how to use it from a Jersey resource. Is that the right approach?</p>
  
  <p>I've been looking through the samples included with Jersey, but haven't found anything yet that illustrates how to do either of these things. If it matters, I'm using Jersey with Jackson to do Object->JSON without the XML step and am not really utilizing JAX-RS. </p>