bhushan_makade Posted September 7, 2010 Share Posted September 7, 2010 Hi,I am using jasper server 3.5 webservice API for scheduling reports from application.We have a requirement of sending the report as zip attachment. From API perspective i could not find a direct way wherein i can specify to zip the particular report.But when i dug into code, i found a code which is doing the compression/zip logicPlease see the attached code.So , just wanted to know if my report has more than one file, then only jasper will implicitely do the compression of that report?or is there any way i can specify to compress a report for me even if it has just one file? Code:protected void attachOutput(MimeMessageHelper messageHelper, ReportOutput output) throws MessagingException, JobExecutionException { String attachmentName; DataContainer attachmentData; if (output.getChildren().isEmpty()) { attachmentName = output.getFilename(); attachmentData = output.getData(); } else { attachmentData = createDataContainer(); boolean close = true; ZipOutputStream zipOut = new ZipOutputStream(attachmentData.getOutputStream()); try { zipOut.putNextEntry(new ZipEntry(output.getFilename())); StreamUtils.pipeData(output.getData().getInputStream(), zipOut); zipOut.closeEntry(); for (Iterator it = output.getChildren().iterator(); it.hasNext();) { ReportOutput child = (ReportOutput) it.next(); String childName = getChildrenFolderName(output.getFilename()) + '/' + child.getFilename(); zipOut.putNextEntry(new ZipEntry(childName)); StreamUtils.pipeData(child.getData().getInputStream(), zipOut); zipOut.closeEntry(); } zipOut.finish(); zipOut.flush(); close = false; zipOut.close(); } catch (IOException e) { throw new JSExceptionWrapper(e); } finally { if (close) { try { zipOut.close(); } catch (IOException e) { log.error("Error closing stream", e); } } } attachmentName = output.getFilename() + ".zip"; } try { attachmentName = MimeUtility.encodeWord(attachmentName, getCharacterEncoding(), null); } catch (UnsupportedEncodingException e) { throw new JSExceptionWrapper(e); } messageHelper.addAttachment(attachmentName, new DataContainerResource(attachmentData)); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now