zoukankan      html  css  js  c++  java
  • invalid stream header: EFBFBDEF 问题解决

    我们项目使用report 报表功能,然后在加载xxxx.jasper文件时候报的invalid stream header: EFBFBDEF 的错误

    public JasperPrint fill(InputStream inputStream, Map<String, Object> parameters)throws JRException{

     JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream); //这里出错

     return fill(jasperReport, parameters);
     }

    跟踪源码主要是下面出错,百思不得其解,网上说很多都是发现字符被改变了以至于ObjectOutputStream无法识别该字符数组所以抛出了java.io.StreamCorruptedException: invalid stream header: EFBFBDEF,可是我这个跟字符串没关系。inputStream读取的是二进制文件,怎么可能出现这个问题。

        ObjectInputStream in = new ObjectInputStream(inputStream);

    偶然看到这篇文章才得以解决https://stackoverflow.com/questions/24078820/java-io-streamcorruptedexception-invalid-stream-header-efbfbdef

    主要是跟maven resource 标签有关系,maven 打包时候,已经把二进制文件给破坏了,导致失败

    <resources>
    <
    resource>
    <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> </resource>
    </resources>

    在maven 网站过滤的时候

    警告:不要过滤包含图像等二进制内容的文件!这很可能会导致输出损坏。如果您同时拥有文本文件和二进制文件作为资源,则需要声明两个互斥的资源集。第一个资源集定义要过滤的文件,另一个资源集定义要保持不变的文件。

    以下则没有问题


    <
    resources> <resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.jasper</exclude> <exclude>**/*.jrxml</exclude> </excludes> </resource> <resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.jasper</include> <include>**/*.jrxml</include> </includes> </resource>
    </
    resources>
    
    
  • 相关阅读:
    模拟_大数字符串(HDU_2054)
    DP_字串匹配(HDU_1501)
    动态字典树_字串标记查找+大数(HDU_4099)
    动态字典树_字串查找匹配(HDU_1075)
    动态字典树+DFS(HDU_1298)
    动态字典树_拆分查找(HDU_1247)
    动态字典树_统计前缀子串(HDU_1251)
    动态字典树_统计子串(HDU_2846)
    字典树讲解
    HTML5语义标签的实践(blog页面)
  • 原文地址:https://www.cnblogs.com/uqing/p/10194471.html
Copyright © 2011-2022 走看看