java.io.StreamCorruptedException:无效的流标头:EFBFBDEF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24078820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
提问by Skizzo
I'm developing an java web application, where I'm using maven like tool of project managmentand now I'm becaming crazy with this problem. I try to build an jasper report from my application, this report is composed from many sub-report that i have in the src/main/resources. I try to load these subreports in the following way:
我正在开发一个 java web 应用程序,在那里我使用 maven 之类的项目管理工具,现在我对这个问题感到疯狂。我尝试从我的应用程序构建一个 jasper 报告,该报告由我在 src/main/resources.js 文件中的许多子报告组成。我尝试通过以下方式加载这些子报表:
//Sub Report 1
InputStream fileSubRep1=(BufferedInputStream) getClass().getResourceAsStream("/fileSubReport1.jasper");
map.put("fileSubRep1",(JasperReport) JRLoader.loadObject(fileSubRep1));
//Sub Report 2
InputStream fileSubRep2=(BufferedInputStream) getClass().getResourceAsStream("/fileSubReport2.jasper");
map.put("fileSubRep1",(JasperReport) JRLoader.loadObject(fileSubRep2));
the problem is that the call at this method JRLoader.loadObject(fileSubRep1)generates the following exception:
问题是调用此方法JRLoader.loadObject(fileSubRep1) 会生成以下异常:
net.sf.jasperreports.engine.JRException: Error loading object from InputStream
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:248)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:228)
at it.aiemonline.report.jasper.GeneraFattureServiceImpl.createMapFileJasper(GeneraFattureServiceImpl.java:292)
at it.aiemonline.report.jasper.GeneraFattureServiceImpl.executeStreamByteFatturaPdf(GeneraFattureServiceImpl.java:890)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at it.aiemonline.utility.logger.SystemLogger.aroundExecuteLog(SystemLogger.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy78.executeStreamByteFatturaPdf(Unknown Source)
at it.aiemonline.vaadin.application.gui.fatturazione.visualizza.VisualizzaFatturaPanel.visualizzaPdf(VisualizzaFatturaPanel.java:236)
at it.aiemonline.vaadin.application.gui.fatturazione.visualizza.VisualizzaFatturaPanel.itemClick(VisualizzaFatturaPanel.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.Table.handleClickEvent(Table.java:3057)
at com.vaadin.ui.Table.changeVariables(Table.java:2853)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:529)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:58)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:243)
... 69 more
Where am I doing wrong? How can I to fix it?
我哪里做错了?我该如何解决?
采纳答案by Skizzo
Finally after 3 day of headache I solved my trouble. I'm using maven like tool of project managment and I'm working on a modular project with this structure
经过三天的头痛,我终于解决了我的麻烦。我正在使用类似 maven 的项目管理工具,并且我正在使用这种结构进行模块化项目
|-- parent
|-- model
--pom.xml
|-- services
--pom.xml
|-- web-app
--pom.xml
The porblem was that the file that I try to load like Input stream was in the src/main/resources in the services module, but in the web-app's pom.xml I enable the resource filtering, and since that web-app module depends of service the filtering was extended at the services module.
问题是,我尝试像输入流一样加载的文件位于服务模块的 src/main/resources 中,但在 web-app 的 pom.xml 中,我启用了资源过滤,因为该 web-app 模块取决于服务的过滤是在服务模块中扩展的。
In filtering section of the maven web site FilteringI found:
在 maven 网站Filtering 的过滤部分中,我发现:
Warning:Do not filter files with binary content like images! This will most likely result in corrupt output. If you have both text files and binary files as resources, you need to declare two mutually exclusive resource sets. The first resource set defines the files to be filtered and the other resource set defines the files to copy unaltered as illustrated below:
警告:不要过滤包含图像等二进制内容的文件!这很可能会导致输出损坏。如果同时拥有文本文件和二进制文件作为资源,则需要声明两个互斥的资源集。第一个资源集定义要过滤的文件,另一个资源集定义要复制的文件,如下图所示:
Then I removed the following code from my web-app module and everything works
然后我从我的 web-app 模块中删除了以下代码,一切正常
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
回答by Théo camb.
Thanks for this solution @skizzo
感谢这个解决方案@skizzo
A less drastic way, if you still need to filter some other files, or copy all the files is simply to include all files you need to filter (java, xml, properties...).
一个不太激烈的方法,如果您仍然需要过滤一些其他文件,或者复制所有文件,只需包含您需要过滤的所有文件(java、xml、属性...)。
Here is the solution I just implemented thanks to your help:
由于您的帮助,这是我刚刚实施的解决方案:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.java</include>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
It didn't seemed related at all, and I was looking for it for several hours already. It really saved my day! ;-)
它似乎根本没有关系,我已经找了好几个小时了。它真的救了我的一天!;-)
回答by hsnkhrmn
In my case, I forgot to exclude compiled jasper reports from end of line fixation ant task. For me below exclusion fixed the issue:
就我而言,我忘记从行尾固定蚂蚁任务中排除已编译的 jasper 报告。对我来说,排除法解决了这个问题:
<fixcrlf srcdir="${basedir}/target/etc"
includes="**/*.*"
excludes="**/*.jasper"
eol="lf" eof="remove"/>
回答by OJVM
I had exactly the same problem, i was solved adding the following plug-in in my pom.xml
我有完全相同的问题,我解决了在 pom.xml 中添加以下插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>jasper</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
回答by Line
For me the reason was not bad Maven configuration. I was simply giving a parameter with wrong name when generating the report.
对我来说,原因不是糟糕的 Maven 配置。我只是在生成报告时给出了一个名称错误的参数。