nextEtnry/closeEntry 上的 ZipInputStream Stream Closed 错误
Posted
技术标签:
【中文标题】nextEtnry/closeEntry 上的 ZipInputStream Stream Closed 错误【英文标题】:ZipInputStream Stream Closed error on nextEtnry/closeEntry 【发布时间】:2020-10-29 21:44:57 【问题描述】:我正在尝试上传 1 个 zip 文件并将其提取到 AWS S3 存储桶中。我收到 Stream Closed 错误:
java.io.IOException: Stream closed
at java.base/java.util.zip.ZipInputStream.ensureOpen(Unknown Source)
at java.base/java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
at com.abc.Handler.extractAndProcessZipFile(Handler.java:115)
这是我的代码 sn-p:
try
ZipInputStream zis = new ZipInputStream(
S3ObjectUtils.getS3Object(S3_INBOUND, FILE_PATH + metadata.getObjectKey(), this.amazonS3Client)
.getObjectContent());
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) //Stream closed Error here when I comment closeEntry()
String fileName = entry.getName();
String srcKey = metadata.getObjectKey().replace('+', ' ');
srcKey = URLDecoder.decode(FILE_PATH + fileMetadata.getObjectKey(), "UTF-8");
// Covert to plain text
String mimeType = "text/plain";
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(entry.getSize());
meta.setContentType(mimeType);
this.amazonS3Client.putObject(S3_IN, FilenameUtils.getFullPath(srcKey) + fileName, zis, meta);
zis.closeEntry(); // Stream Closed error here
zis.close();
catch (IOException e)
e.printStackTrace();
【问题讨论】:
【参考方案1】:已通过删除 zis.closeEntry 并将 while 更改为 if 进行修复
【讨论】:
以上是关于nextEtnry/closeEntry 上的 ZipInputStream Stream Closed 错误的主要内容,如果未能解决你的问题,请参考以下文章