Is there a way to set a limit on the size of a JasperReport? We just looked at a WebSphere 6.1 Heapdump and someone tried to create a report and it was 1.5GB of memory in the h
I'm not familiar with JasperReports, but you could wrap your I/O streams to ensure that the amount of data read/written does not exceed a defined limit.
OutputStream example:
public class LimitedSizeOutputStream extends OutputStream {
private final OutputStream delegate;
private final long limit;
private long written = 0L;
/**
* Creates a stream wrapper that will throw an IOException if the write
* limit is exceeded.
*
* @param delegate
* the underlying stream
* @param limit
* the maximum number of bytes this stream will accept
*/
public LimitedSizeOutputStream(OutputStream delegate, long limit) {
this.delegate = delegate;
this.limit = limit;
}
private void checkLimit(long byteCount) throws IOException {
if (byteCount + written > limit) {
throw new IOException("Exceeded stream size limit");
}
written += byteCount;
}
@Override
public void write(int b) throws IOException {
checkLimit(1);
delegate.write(b);
}
@Override
public void write(byte[] b) throws IOException {
checkLimit(b.length);
delegate.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
checkLimit(len);
delegate.write(b, off, len);
}
@Override
public void close() throws IOException {
delegate.close();
}
}
It is just as easy to wrap an InputStream.
Have you tried limiting the rows in the recordset returned from the database?
JasperReports now has "report governors" that limit the size of report output. For example, you can set these config params:
net.sf.jasperreports.governor.max.pages.enabled=[true|false]
net.sf.jasperreports.governor.max.pages=[integer]
See this posting on the JasperReports forums for more info.