I'm trying to use zip4j on password protected zip files received through a ZipInputStream. It's mostly working well, but I have a .zip file with subdirectories and when I'm looping over it I am only seeing the one directory.
Minimal example:
- Create a password protected zip with one directory in it with 1 file in that (I chose the password "password" for simplicity). Your zip will look like this:
$ unzip -l test_dir.zip
Archive: test_dir.zip
Length Date Time Name
--------- ---------- ----- ----
0 07-04-2021 21:36 test_dir/
0 07-04-2021 21:36 test_dir/test_file
--------- -------
0 2 files
- Load the zip in with a ZipInputStream
public void minimalExample() throws IOException {
InputStream inputStream = getClass().getResourceAsStream("test_dir.zip");
LocalFileHeader localFileHeader;
ZipInputStream zipInputStream = new ZipInputStream(inputStream, "password".toCharArray());
while ((localFileHeader = zipInputStream.getNextEntry()) != null) {
Log.w("File found:", localFileHeader.getFileName());
}
}
The output will be as follows if the .zip is password-protected:
W/File found:: test_dir/
(So, the test_dir/test_file is not found! This works if it is not password-protected)
Anyone have any tips on what I may be doing wrong?