我有大型 Base64 编码的 Gzipped 数据存储在 tomcat 临时文件夹中的 .tmp 文件中。该数据最初是 gzip 压缩的文本数据。我需要能够读取这些编码数据的块,对其进行解码,然后使用 GZIPInputStream 将其解压缩。但是我在 zis.read(decodedChunk) 得到了这个 ZipException: invalid bit length repeat 异常。我正在使用来自 apache-commons-codec 1.10 的 Base64InputStream。请分享您的专家建议以解决此问题。
Base64InputStream b64is = new Base64InputStream(
Files.newInputStream(tempFile2, StandardOpenOption.READ));
GZIPInputStream zis = new GZIPInputStream(b64is);
Path tempFile3 = Files.createTempFile("Decodedfile", ".tmp");
BufferedOutputStream decodedStream = new BufferedOutputStream(
Files.newOutputStream(tempFile3,
StandardOpenOption.CREATE, StandardOpenOption.APPEND), BUFFER);
int count1;
byte[] decodedChunk = new byte[512];
while ((count1 = zis.read(decodedChunk)) != -1) { // ZipException here
System.out.println("\n zis count : %d " + count1);
decodedStream.write(decodedChunk, 0, count1);
}
decodedStream.flush();
decodedStream.close();
zis.close();
b64is.close();
错误堆栈跟踪——
java.util.zip.ZipException: invalid bit length repeat
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
at it.customercare.WebDetails.GenerateOrgUserReport.getUsersReport
(GenerateOrgUserReport.java:420)
at it.customercare.WebDetails.HostContactAPIClient.callAPI
(HostContactAPIClient.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at it.customercare.WebDetails.HostContactAPIClient.callAPI
(HostContactAPIClient.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.jersey.server.model.internal.
ResourceMethodInvocationHandlerFactory$1.invoke
(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.
AbstractJavaResourceMethodDispatcher$1.run
(AbstractJavaResourceMethodDispatcher.java:144)
at org.glassfish.jersey.server.model.internal.
AbstractJavaResourceMethodDispatcher.invoke
(AbstractJavaResourceMethodDispatcher.java:161)
at org.glassfish.jersey.server.model.internal.
JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch
(JavaResourceMethodDispatcherProvider.java:205)
at org.glassfish.jersey.server.model.internal.
AbstractJavaResourceMethodDispatcher.dispatch
(AbstractJavaResourceMethodDispatcher.java:99)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:309)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
FailedToInvokeService - 失败。
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)