/** * Saves the rendered report to the specified DeliverFile component, which the caller will return * back to the user. * * @param file the DeliverFile component to save the file into * @return a Throwable if an error occurred (which the caller should display to the user), or null * if the operation was successful */ public Throwable deliverTo(DeliverFile file) { try { NSMutableDataOutputStream outputStream = new NSMutableDataOutputStream(); PDFRenderOption option = new PDFRenderOption(); option.setOutputFormat("PDF"); option.setOutputStream(outputStream); IRenderTask task = reportEngine().createRenderTask(reportDocument()); task.setRenderOption(option); org.mozilla.javascript.Context.enter(); task.render(); org.mozilla.javascript.Context.exit(); outputStream.close(); close(); file.setFileData(outputStream.data()); file.setContentType("application/pdf"); file.setStartDownload(true); file.setDeliveredName(generatedReport().description() + ".pdf"); } catch (Exception e) { return e; } return null; }
/** * Gets the contents of the specified blob as raw data. * * @param objectId the id of the blob * @return an {@code NSData} object containing the raw data from the blob */ public NSData contentForBlob(ObjectId objectId) { ObjectReader reader = repository.newObjectReader(); try { ObjectLoader loader = reader.open(objectId); NSMutableDataOutputStream output = new NSMutableDataOutputStream(); loader.copyTo(output); output.close(); return output.data(); } catch (IOException e) { log.error("An exception occurred while getting the blob " + "contents: ", e); return null; } finally { reader.release(); } }