通过扩展
StreamingOutput对象,我设法获得了ZIP文件或PDF文件。这是一些示例代码:
@Path("PDF-file.pdf/")@GET@Produces({"application/pdf"})public StreamingOutput getPDF() throws Exception { return new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { try { PDFGenerator generator = new PDFGenerator(getEntity()); generator.generatePDF(output); } catch (Exception e) { throw new WebApplicationException(e); } } };}PDFGenerator类(我自己的用于创建PDF的类)从write方法获取输出流并将其写入,而不是新创建的输出流。
不知道这是否是最好的方法,但是它有效。



