gpt4 book ai didi

tomcat - java.io.IOException : unexpected EOF with 512 bytes unread 异常

转载 作者:行者123 更新时间:2023-11-28 22:20:02 27 4
gpt4 key购买 nike

我正在尝试解压缩从服务器获得的响应,但出现异常。这是方法:

 public InputStream getResource(@PathParam("id") String envId, @PathParam("appName") String appName, @PathParam("imageType") String imageType,
@QueryParam("resourcePath") String resourcePath) throws EnvAutomationException, IOException, InterruptedException {Environment env = Envs.getEnvironmentManager().findEnvironment(envId);
ApplicationInstance appInst = env.getApplicationInstance(appName);
Container container = appInst.getContainer(imageType);
InputStream resource = Envs.getContainerizationManager().getResource(container, resourcePath);

if (resource != null && resource.available() > 0) {
TarInputStream myTarStream = new TarInputStream(resource);
TarEntry entry = myTarStream.getNextEntry();
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] content = new byte[1024];
int offset = 0;
while ((offset = myTarStream.read(content)) > 0) {
output.write(content, 0, offset);
}

output.flush();
byte[] bo = output.toByteArray();
InputStream lastSentValues = new ByteArrayInputStream(bo);
return lastSentValues;
}
return null;

}

我得到了这个异常:2014 年 7 月 16 日下午 5:05:05 org.apache.catalina.core.StandardWrapperValve 调用
严重:servlet [eu.eee.envs.api.JaxRsActivator] 在路径 [/SQAutomationServer] 上下文中的 Servlet.service() 抛出异常 [org.glassfish.jersey.server.ContainerException: java.io.IOException: unexpected EOF with 512 字节未读] 有根本原因
java.io.IOException:意外的 EOF,有 512 个字节未读

at org.codehaus.plexus.archiver.tar.TarInputStream.read(TarInputStream.java:376)
at org.codehaus.plexus.archiver.tar.TarInputStream.read(TarInputStream.java:314)
at eu.eee.envs.api.Resources.getResource(Resources.java:44)
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)

最佳答案

我最近遇到了类似的问题。

更改此代码。

while ((offset = myTarStream.read(content)) > 0) {
output.write(content, 0, offset);
}

   while ((offset = myTarStream.read(content,0,1024)) != -1) {
output.write(content, 0, offset);
}

关于tomcat - java.io.IOException : unexpected EOF with 512 bytes unread 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24784649/

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