JasperReport大小限制

时间:2009-02-13 03:09:06

标签: java jasper-reports

有没有办法设置JasperReport的大小限制?我们只看了一下WebSphere 6.1 Heapdump,有人试图创建一个报告,堆中有1.5GB的内存。它让我们的Websphere服务器瘫痪了。 谢谢, Ť

3 个答案:

答案 0 :(得分:2)

我不熟悉JasperReports,但您可以wrap your I/O streams确保读/写的数据量不超过定义的限制。

OutputStream示例:

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();
    }

}

包装InputStream同样容易。

答案 1 :(得分:1)

JasperReports现在有“报告管理员”,它限制了报告输出的大小。例如,您可以设置这些配置参数:

<强> net.sf.jasperreports.governor.max.pages.enabled=[true|false]

<强> net.sf.jasperreports.governor.max.pages=[integer]

有关详细信息,请参阅JasperReports论坛上的this posting

答案 2 :(得分:0)

您是否尝试过限制从数据库返回的记录集中的行?