JasperReport大小限制 [英] JasperReport size limit

查看:470
本文介绍了JasperReport大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 heap. And it brought our Websphere server to its knees. Thanks, T

推荐答案

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

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 示例:

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

这篇关于JasperReport大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆