nextEtnry/closeEntry 上的 ZipInputStream 流关闭错误
ZipInputStream Stream Closed error on nextEtnry/closeEntry
我正在尝试上传 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)
这是我的代码片段:
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();
}
已通过删除 zis.closeEntry 进行修复并将 while 更改为 if
我正在尝试上传 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)
这是我的代码片段:
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();
}
已通过删除 zis.closeEntry 进行修复并将 while 更改为 if