This discussion is archived
1 Reply Latest reply: Feb 7, 2010 11:21 PM by 791266 RSS

Could this unclosed() byteArrayInputStream cause high Heap usage ?

843798 Newbie
Currently Being Moderated
Hi all,

As part of our reporting integrated with our JSF/JSP application, the
report is converted to PDF then sent to browser for user to display.
mean while during peak load our Heap usage could reach 3.5GB - 4GB. So
I am suspecting the unclosed byteArrayInputStream is the cause.
(This is a production application so I am collecting information
before change the code)


Is the unclosed() byteArrayInputStream really cause the problem ?
(the codes is below)


Thank you,
Krist


ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)


reportClientDoc.getPrintOutputController().export(exportOptions);
reportClientDoc.close();
writeToBrowser(byteArrayInputStream, response, "application/csv",
EXPORT_FILE);


private void writeToBrowser(ByteArrayInputStream byteArrayInputStream,
HttpServletResponse
response, String mimetype, String exportFile)
throws Exception {
byte[] buffer = new byte[byteArrayInputStream.available()];
int bytesRead = 0;
response.reset();
response.setHeader("Content-disposition", "inline;filename=" +
exportFile);
response.setContentType(mimetype);
//Stream the byte array to the client.
while((bytesRead = byteArrayInputStream.read(buffer)) != -1)
{ response.getOutputStream().write(buffer , 0,
bytesRead);}


//Flush and close the output stream.
response.getOutputStream().flush();
response.getOutputStream().close();
}