I have a web server project, i get an exception while trying to download large files. The file is read and written to ServletOutputStream via streams.
Sample code :
private void readFromInput(BufferedInputStream fis,
ServletOutputStream sout) throws IOException
{
byte[] buf = new byte[4096];
int c = 0;
while ((c = fis.read(buf)) != -1)
{
sout.write(buf, 0, c);
}
fis.close();
}
When i look at the backtrace, i see some filters are executed.
Here is the some parts of the exception :
javax.servlet.ServletException: #{DownloaderBean.actionDownload}:
java.lang.OutOfMemoryError: Java heap space
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
....
....
....
java.lang.OutOfMemoryError: Java heap space
java.io.ByteArrayOutputStream.write(Unknown Source)
org.apache.myfaces.webapp.filter.ExtensionsResponseWrapper$MyServletOutputStream.write(ExtensionsResponseWrapper.java:135)
When i look at that ExtensionFilter code :
There is a part on this page :
"When the ExtensionsFilter is enabled, and the DefaultAddResources implementation is
used then there is no way to avoid having the response buffered in memory"
I guess these filters buffer the response on heap and cause the problem. Is there a way to prevent this filters apply on a spesific page/link? Or should i follow another way to handle this?