We store zip files on S3 and consume the stream of selected entries using the following code:
final ZipInputStream zipStream = new ZipInputStream(s3ObjectInputStream) {
@Override
public void close() throws IOException {
// Drain before closing to keep S3 client happy
while (getNextEntry() != null);
while (read() >= 0);
super.close();
}
};
ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
if (entryFilter.matches(entry.getName())) {
return zipStream;
}
}
Even though we fully drain the stream before closing it, the warning persists. What are we doing wrong?
What version of the SDK are you using? Can you share the wirelog (Do not include sensitive data)?
ZIP archives have a (redundant) central directory structure at the end, so you can list the contents of the archive without scanning through the whole thing. Java's ZipInputStream never actually consumes this from the underlying stream; getNextEntry() returns null as soon as it finds the start of the central directory.
You might try adding while (in.read() >= 0); in your overridden close method to read through to the end of the underlying stream?
@axelfontaine
Did you try the fix mentioned by @fernomac? Let us know if you still have the issue.
This seems to have resolved it. Thanks!
Most helpful comment
ZIP archives have a (redundant) central directory structure at the end, so you can list the contents of the archive without scanning through the whole thing. Java's
ZipInputStreamnever actually consumes this from the underlying stream;getNextEntry()returns null as soon as it finds the start of the central directory.You might try adding
while (in.read() >= 0);in your overridden close method to read through to the end of the underlying stream?