Tenho o seguinte código que estou usando como teste para implementar um servidor de arquivos, mas ao tentar baixar arquivos de 5mb ou mais ele da o erro OutOfMemoryError Java heap space.
Implementei o mesmo código num servlet separado e não deu o erro.
O problema é no JSF ?
<h:form id="teste">
<h:commandLink action="#{ArquivoDownload.download}" value="Download Teste" immediate="true"/>
</h:form>
public class ArquivoDownload {
private File[] fileArray = new File("C:/Users/pirm/Downloads/").listFiles();
private String path = "C:/Users/pirm/Downloads/netbeans-6.8-ml-windows.exe";
public File[] getFileArray() {
return fileArray;
}
public void setFileArray(File[] fileArray) {
this.fileArray = fileArray;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public synchronized void download() {
System.out.println("Metodo download()");
File file = new File(path);
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
response.setContentLength((int) file.length());
System.out.println("Arquivo: " + file.getName() + " " + file.getAbsolutePath() + " " + file.length());
try {
FileInputStream input = new FileInputStream(file);
ServletOutputStream out = response.getOutputStream();
byte[] buffer = new byte[1024];
int i;
while ((i = input.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
out.flush();
out.close();
input.close();
facesContext.getResponseComplete();
} catch (IOException err) {
err.printStackTrace();
}
}
}
Alguem já passou pelo problema ???
desconsidere o post de antes ^^