i would like not to download the BufferedOutputStream
when return java method.
my code:
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setHeader("Content-Disposition", "attachment; filename=\"" + "Invoice.zip\";");
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
ZipOutputStream zos = new ZipOutputStream(bos);
for(SalesEInvObject InvoiceObj : this.InvoiceTable){ // MAIN FOR-LOOP STARTS
if (InvoiceObj.getInvoiceNo() != null) {
javax.servlet.http.HttpSession httpSession =(javax.servlet.http.HttpSession) ctx.getExternalContext().getSession(false);
httpSession.setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,
reportOutput.getInternalReportObject());
byte[] bytes = reportOutput.getReportOutputBytes();
int length = ((bytes == null) ? 0 : bytes.length);
response.setContentLength(length*tableSize);
final ZipEntry ze = new ZipEntry(reportOutputFileName+".pdf");
zos.putNextEntry(ze);
zos.write(bytes, 0, bytes.length);
zos.closeEntry();
}else {
return null;
}
}//LOOP ENDS
zos.close();
ctx.responseComplete();
my problem is when the invoices has Number it generates invoice and download in compressed zip file. but when it has no Number i dont want to download zip. but still zip file downloads but with empty no file in it.
if no pdf generated i dont want to download zip file.
any help...