gpt4 book ai didi

java - JasperReport 大小限制

转载 作者:行者123 更新时间:2023-12-04 07:09:56 26 4
gpt4 key购买 nike

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

最佳答案

我不熟悉 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 也很容易.

关于java - JasperReport 大小限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/544581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com