首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >StreamResource,ByteArray问题

StreamResource,ByteArray问题
EN

Stack Overflow用户
提问于 2014-06-17 11:05:55
回答 1查看 820关注 0票数 0

我不明白为什么我的代码没有一直运行。我正在打开jasper报告,但是对于前4个打开时间,报告被缓存或代码没有执行(新StreamResource中的代码没有执行前4次)。新的StreamResource.StreamSource()只在5次运行,为什么?前4次,我得到了旧的,缓存的,临时的或我的事件不知道什么pdf文件与旧的帕拉姆。

也许有人知道这个问题?

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2014-06-18 06:41:50

在这里is的答案

我一直使用resource.setCacheTime(0);,但真的需要resource.setCacheTime(1000);,因为

理论上,<= 0禁用缓存。在实践中,Chrome、Safari (显然还有IE)都忽略了<=0。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24262174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档