java.util.zip.DataFormatException:数据检查不正确
Posted
技术标签:
【中文标题】java.util.zip.DataFormatException:数据检查不正确【英文标题】:java.util.zip.DataFormatException: incorrect data check 【发布时间】:2015-06-10 17:59:54 【问题描述】:我在加载 JSF 页面时遇到了下面提到的错误。页面加载成功,页面上所需的操作也完成了,但是出现了这个错误。
JSF 页面包含选项卡面板,如果我尝试将可用项目中的某些项目包含到包含的项目中,则会出现错误。以下是列表的 Xhtml。
<a4j:outputPanel id="selectItems">
<div id="div_selectItems" class="scroll_container">
<s:div styleClass="dialogueAttribute">
<rich:listShuttle sourceValue="#itemReportEditor.itemsList"
targetValue="#itemReportEntry.itemReportData"
var="items"
listsHeight="28em"
sourceListWidth="45em"
targetListWidth="45em"
sourceCaptionLabel="Available Items"
targetCaptionLabel="Included Items"
removeAllControlLabel="Remove all"
removeControlLabel="Remove"
copyControlLabel="Add"
copyAllControlLabel="Add all"
fastOrderControlsVisible="true"
orderControlsVisible="true"
converter="#itemReportEditor.itemReportDataModelConverter">
<rich:column>
<f:facet name="header">
<h:outputText title="Performance item name"
value="Name"/>
</f:facet>
<h:outputText value="#items['itemName']"></h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText title="Performance Item Protocol"
value="Protocol"/>
</f:facet>
<h:outputText value="#items['protocol']"></h:outputText>
</rich:column>
<a4j:support event="onlistchanged"
action="#itemReportEntry.updateItemsList()"
reRender="la"
oncomplete="resizeScrollBox2();"
status="workingStatus"
eventsQueue="ajaxQueue"/>
</rich:listShuttle>
</s:div>
</div>
</a4j:outputPanel>
我正在尝试使用列表穿梭从左侧到右侧添加一些项目,并且在日志中出现以下异常(仅在 FireFox 浏览器中,未在 Google Chrome 中观察到此问题)(能够应用所有更改正确,只是得到以下异常)。我的 FireFox 版本是 35.0.1
2015-04-06 15:42:34,272 ERROR [http-0.0.0.0-8080-8] org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/client].[Faces Servlet]
Servlet.service() for servlet Faces Servlet threw exception
javax.faces.FacesException: Error decode resource data
at org.ajax4jsf.resource.ResourceBuilderImpl.decrypt(ResourceBuilderImpl.java:627)
at org.ajax4jsf.resource.ResourceBuilderImpl.getResourceDataForKey(ResourceBuilderImpl.java:369)
at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:156)
at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:141)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.util.zip.DataFormatException: incorrect data check
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:238)
at java.util.zip.Inflater.inflate(Inflater.java:256)
at org.ajax4jsf.resource.ResourceBuilderImpl.decrypt(ResourceBuilderImpl.java:621)
... 30 more
谷歌搜索我发现“问题似乎是像'!'这样的字符由 FireFox 转换为 '%21'。以下过滤器会将 %21 转换回 '!'所以资源可以在服务器中找到”
就我而言,我只是在日志中收到异常,但所有源都已成功加载
为了消除异常,我添加了过滤器
package juno.sa.server;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
public class RichFacesFirefox11Filter implements Filter
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
chain.doFilter(new HttpServletRequestWrapper((HttpServletRequest) request)
@Override
public String getRequestURI()
try
return URLDecoder.decode(super.getRequestURI(), "UTF-8");
catch (UnsupportedEncodingException e)
throw new IllegalStateException("Cannot decode request URI.", e);
, response);
@Override
public void init(FilterConfig filterConfig) throws ServletException
// do nothing
@Override
public void destroy()
// do nothing
<filter>
<filter-name>RichFacesFirefox11Filter</filter-name>
<filter-class>juno.sa.server.RichFacesFirefox11Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>RichFacesFirefox11Filter</filter-name>
<url-pattern>*.seam</url-pattern>
</filter-mapping>
【问题讨论】:
那么如果您的资源正在加载并且过滤器阻止了异常,那么问题是什么? 资源已加载,但我在日志中收到异常,我不想出现该异常 【参考方案1】:即使我收到这样的异常。 引起:java.util.zip.ZipException:数据检查不正确 在 java.util.zip.InflaterInputStream.read(InflaterInputStream.java:147)
但在我的情况下,根本原因是我尝试读取的流是使用 flate 编码器压缩的,因此尝试解压缩的流是 InflaterInputStream。
在我的情况下,最后一个字节中存在的数据不是 eof 参数,而是实际数据,eof 参数存在于流中最后一个字节之前的某个位置。因此,当流读取块数据的最后一个字节时,它无法找到 eof 从而引发不正确的数据检查。
也许在你的最后验证它......它也可能在你的最后是同样的问题。
【讨论】:
以上是关于java.util.zip.DataFormatException:数据检查不正确的主要内容,如果未能解决你的问题,请参考以下文章