gpt4 book ai didi

java - 尝试使用ZipInputStream解压缩String值时,获取IOException推回缓冲区已满

转载 作者:行者123 更新时间:2023-12-03 11:18:32 26 4
gpt4 key购买 nike

我正在尝试解压缩String值。
但是我得到了java.io.IOException: Push back buffer is full:

public byte[] unzipArray(String stringToUnzip) {
byte[] inputByteArray = Base64.decode(stringToUnzip);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
inputByteArray);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream);

try {
ZipEntry theEntry = zipInputStream.getNextEntry();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] buffer = new byte[2048];
int size = 2048;

while (true) {
try {
size = zipInputStream.read(buffer, 0, buffer.length);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (size > 0) {
byteArrayOutputStream.write(buffer, 0, size);
} else {
break;
}
}
return byteArrayOutputStream.toByteArray();
}

异常堆栈跟踪:
java.io.IOException: Push back buffer is full
at java.io.PushbackInputStream.unread(Unknown Source)
at java.util.zip.ZipInputStream.readEnd(Unknown Source)
at java.util.zip.ZipInputStream.read(Unknown Source)
at com.ZipHelper.unzipArray(ZipHelper.java:55)
......
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.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:168)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:530)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:427)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.server.session.SessionHandler.handle(SessionHandler.java:182)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:933)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:362)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:867)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
at org.eclipse.jetty.server.Server.handle(Server.java:334)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:559)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1007)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:747)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:209)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:462)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:436)
at java.lang.Thread.run(Unknown Source)

最佳答案

没有足够的证据来确定异常的真正原因,但是我可以在您的代码中看到一个重大问题:
您执行以下操作以获取ZIP文件的第一个条目:

  ZipEntry theEntry = zipInputStream.getNextEntry();
但是您不会测试 theEntry是否为 null。如果它是 null,则表示该ZIP文件没有任何条目。
然后,您继续使用 read。它被指定为从“当前条目”中读取,但是javadoc没有说明如果没有当前条目会发生什么。

关于java - 尝试使用ZipInputStream解压缩String值时,获取IOException推回缓冲区已满,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2628340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com