将zipInputSteam的数据读取到byte数组里面的时候报错

qiaogr138 2012-03-10 11:48:52
java.util.zip.ZipException: invalid entry size (expected 61268 but got 61695 bytes)


private static byte[] getData(InflaterInputStream zis) {
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] temp = new byte[3072];
byte[] buf = null;
int length = 0;

System.out.println(zis.available());

while ((length = zis.read(temp, 0, 3072)) != -1) {
bout.write(temp, 0, length);
}

buf = bout.toByteArray();
bout.close();
return buf;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

zis是zipInputStream的对象。这个是什么原因造成的,有什么解决办法??
...全文
142 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiaogr138 2012-03-11
  • 打赏
  • 举报
回复
先从ftp上面拉下来一个文件的inputStream,有文件的文件名称传给public static List<Map<String, InputStream>> ReadZip(InputStream inputStream) {

List<Map<String, InputStream>> inList = new ArrayList<Map<String, InputStream>>();

try {

// 创建输入字节流
// 根据输入字节流创建输入字符流
BufferedInputStream bis = new BufferedInputStream(inputStream);
// 根据字符流,创建ZIP文件输入流
ZipInputStream zis = new ZipInputStream(bis);
// zip文件条目,表示zip文件
ZipEntry entry;
// 循环读取文件条目,只要不为空,就进行处理

entry = zis.getNextEntry();
while ((entry = zis.getNextEntry()) != null) {
String entryName = entry.getName();
// 如果条目是文件目录,则继续执行
if (entry.isDirectory()) {
continue;
} else {
byte[] bytes = getData(zis);
Map<String, InputStream> map = new HashMap<String, InputStream>();
InputStream in = new ByteArrayInputStream(bytes);
map.put(entryName, in);
inList.add(map);
}
}
bis.close();
zis.close();
} catch (Exception e) {
e.printStackTrace();
}

return inList;
}这个方法。在这里面调用getData();
MiceRice 2012-03-10
  • 打赏
  • 举报
回复
从错误来看,似乎是原始的压缩流出问题了,预期的文件大小是61268,但实际读取了61695。

zis是怎么来的?

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧