web-dev-qa-db-ja.com

java.io.StreamCorruptedException:無効なストリームヘッダー:EFBFBDEF

私はJava Webアプリケーションを開発しています。ここでは、プロジェクト管理のツールのようなMavenを使用していますが、今ではこの問題に夢中になっています。アプリケーションからジャスパーレポートを作成しようとしています。このレポートは、src/main/resourcesにある多くのサブレポートで構成されており、次の方法でこれらのサブレポートをロードしようとしています。

//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));

問題は、このメソッドを呼び出すと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$1.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$1.run(SelectChannelEndPoint.Java:40)
    at org.Eclipse.jetty.util.thread.QueuedThreadPool$3.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

私はどこで間違っているのですか?どうすれば修正できますか?

14
Skizzo

ついに3日間の頭痛の後、私は自分の問題を解決しました。私はプロジェクト管理のツールのようなMavenを使用しており、この構造のモジュラープロジェクトに取り組んでいます

|-- parent
   |-- model
    --pom.xml
   |-- services
    --pom.xml
   |-- web-app
    --pom.xml

問題は、入力ストリームのようにロードしようとするファイルがサービスモジュールのsrc/main/resourcesにあることでしたが、web-appのpom.xmlでリソースフィルタリングを有効にし、そのweb-appモジュールはサービスのフィルタリングは、サービスモジュールで拡張されました。

Maven Webサイトのフィルタリングセクションで フィルタリング 私は見つけました:

警告:画像のようなバイナリコンテンツを含むファイルをフィルタリングしないでください!これにより、出力が破損する可能性があります。リソースとしてテキストファイルとバイナリファイルの両方がある場合は、相互に排他的な2つのリソースセットを宣言する必要があります。以下に示すように、最初のリソースセットはフィルタリングするファイルを定義し、他のリソースセットは変更せずにコピーするファイルを定義します。

次に、Webアプリモジュールから次のコードを削除すると、すべてが機能します

<resources>
     <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
    </resource>
</resources>
38
Skizzo

このソリューションをありがとう@skizzo

他のファイルをフィルタリングする必要がある場合、またはすべてのファイルをコピーする必要がある場合は、それほど抜本的な方法ではありません。フィルタリングする必要のあるすべてのファイル(Java、xml、プロパティなど)を含めるだけです。

これがあなたの助けのおかげで私がちょうど実装した解決策です:

        <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>

それはまったく関係がないようで、私はすでに数時間それを探していました。それは本当に私の一日を救った! ;-)

4
Théo camb.

私はまったく同じ問題を抱えていました、私は私の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>
3
OJVM

私の場合、コンパイルされたジャスパーレポートを行末固定Antタスクから除外するのを忘れていました。以下の除外で問題が修正されました。

<fixcrlf srcdir="${basedir}/target/etc"
    includes="**/*.*"
    excludes="**/*.jasper"
    eol="lf" eof="remove"/>
1
hsnkhrmn

私にとって、その理由は悪いMaven構成ではありませんでした。レポートを生成するときに、間違った名前のパラメーターを指定しただけです。

0
Line