Currently I am using jasper v 3.7.4
While exporting to any other format (csv,xls,pdf) from the same dataset - I have has no issues.
Exporting to text throws:
java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3236) at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
Here is my code:
byte[] bytes = null;
JRTextExporter exporter = new JRTextExporter();
ByteArrayOutputStream txtReport = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, txtReport);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "mytxt.txt");
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, 2.0F);
exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, 100.0F);
exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, 4.0F);
exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, 50.0F);
exporter.exportReport();
bytes = txtReport.toByteArray();
FileOutputStream fos = new FileOutputStream("c:\\myfile.txt")
System.out.println(bytes.length/1024+" Kbytes");
fos.write(bytes, 0, bytes.length);
fos.flush();
fos.close();
I am also using a virtualizer as jasperPrint parameter
JRFileVirtualizer virtualizer = new JRFileVirtualizer(150);
virtualizer.setReadOnly(false);
params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
But it does not help, and also the following warning is shown:
WARNING: Parameter "REPORT_VIRTUALIZER" already registered, skipping this one.
Given that csv is also a "text" file and is generated without any problem, it is kind of strange that
exporting to text fails.
May be something is wrong with the parameters I provide for the exporter?
Thanks.
ByteArrayOutputStreamis to be able to setresponse.setContentLength(bytes.length);on servlet's response but if I write directly to the stream I have no knowledge of content length ... is there a way to obtain that information ?