Java 河流资源,ByteArray问题

Java 河流资源,ByteArray问题,java,stream,jasper-reports,byte,Java,Stream,Jasper Reports,Byte,我不明白为什么我的代码没有一直运行。 我正在打开一个jasper报表,但在前4次打开时,报表被缓存或代码未执行(新StreamResource中的代码未执行前4次)。new StreamResource.StreamSource()仅在5次运行为什么?前4次我得到旧的、缓存的、临时的或我不知道什么是带有旧参数的pdf文件 也许有人知道这个问题 public static void open(final String fileName, final HashMap<String, Objec

我不明白为什么我的代码没有一直运行。 我正在打开一个jasper报表,但在前4次打开时,报表被缓存或代码未执行(新StreamResource中的代码未执行前4次)。new StreamResource.StreamSource()仅在5次运行为什么?前4次我得到旧的、缓存的、临时的或我不知道什么是带有旧参数的pdf文件

也许有人知道这个问题

public static void open(final String fileName, final HashMap<String, Object> data ) {
    mylog.pl("@@@ Param's print @ open Report: Filename:" + fileName);
    try {
        Iterator<?> i = data.keySet().iterator();
        while (i.hasNext()) {
            String id = i.next().toString();
            String value = (data.get(id) != null) ? data.get(id).toString() : "null";
            mylog.pl(" id: " + id + " value: " + value);
        }
    } catch (Exception e) {
        e.printStackTrace();
        mylog.pl(e.getMessage());
    }
    StreamResource.StreamSource source = null;
    source = new StreamResource.StreamSource() {
        public InputStream getStream() {
            byte[] b = null;
            InputStream reportStream = null;
            try {
                reportStream = new BufferedInputStream(new FileInputStream(PATH + fileName + JASPER));
                b = JasperRunManager.runReportToPdf(reportStream, data, new JREmptyDataSource());
            } catch (JRException ex) {
                ex.printStackTrace();
                mylog.pl("Err @ JR" + ex.getMessage());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                Utils.showMessage(SU.NOTFOUND);
                return null;
            }
            return new ByteArrayInputStream(b);
        }
    };
    StreamResource resource = null;
    resource = new StreamResource(source, fileName + PDF);
    resource.setMIMEType("application/pdf");
    Page p = Page.getCurrent();
    p.open(resource, "Report", false);
}
publicstaticvoidopen(最终字符串文件名,最终HashMap数据){
pl(“@@@Param的print@open Report:Filename:”+Filename);
试一试{
迭代器i=data.keySet().Iterator();
while(i.hasNext()){
字符串id=i.next().toString();
字符串值=(data.get(id)!=null)?data.get(id).toString():“null”;
pl(“id:+id+”值:+value”);
}
}捕获(例外e){
e、 printStackTrace();
pl(e.getMessage());
}
StreamResource.StreamSource source=null;
source=新的StreamResource.StreamSource(){
公共输入流getStream(){
字节[]b=null;
InputStream reportStream=null;
试一试{
reportStream=newbufferedInputstream(newfileinputstream(PATH+fileName+JASPER));
b=JasperRunManager.runReportToPdf(reportStream,data,newjreportydatasource());
}捕获(JREX异常){
例如printStackTrace();
pl(“Err@JR”+ex.getMessage());
}catch(filenotfounde异常){
e、 printStackTrace();
Utils.showMessage(SU.NOTFOUND);
返回null;
}
返回新的ByteArrayInputStream(b);
}
};
StreamResource=null;
资源=新的StreamResource(源,文件名+PDF);
resource.setMIMEType(“application/pdf”);
Page p=Page.getCurrent();
p、 打开(资源,“报告”,错误);
}
这里是答案

I一直使用
resource.setCacheTime(0)但确实需要
资源.setCacheTime(1000)因为

理论上