Records can be obtained from a website and displayed on the screen or the file can be downloaded in csv format. when the arrayList has more than 60 thousand registers it gives me the error
java.lang.OutOfMemoryError: Java heap space
what am I doing wrong ??
this is the code
HTML
function getFile(){
success: function (data){
if(data.estado === 'success'){
download(data.nombre,data.file);
}
}
function download(filename, data) {
var element = document.createElement('a');
element.setAttribute('href', data );
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
JAVA
ArrayList<ExcedentesVO> listado = new ArrayList<ExcedentesVO>();
try{
listado = dao.getRegistrosFile();
if(listado.size() > 0){
String file = crearArchivo(listado);
json.put("estado","success");
json.put("file", file);
}
private String crearArchivo(List<ExcedentesVO> list) throws Exception {
StringBuilder archivo = new StringBuilder();
for (Object vo : list) {
archivo.append(vo.getxxx+";"+vo.getxxxx+";"+vo.getxxxx+"\n");
}
byte[] bytesEncoded = Base64.encodeBase64(archivo.toString().getBytes());
String file = csv+new String(bytesEncoded);
return file;
}
ERROR
]] Root cause of ServletException.
java.lang.OutOfMemoryError: Java heap space
at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:149)
at java.lang.StringCoding.decode(StringCoding.java:193)
at java.lang.StringCoding.decode(StringCoding.java:254)
at java.lang.String.<init>(String.java:546)
at java.lang.String.<init>(String.java:566)
Truncated. see log file for complete stacktrace
>