ZipFile inside ZipFile

I have a zip file that can contain any number of zip files inside it (recursively). I need to sort through all of them.

Right now I have a function that takes zipInputStream and zipFile as parameters. Problem in; if I get a zip inside another zip, I call this function again again. Therefore, I do not know how to create a zipFile object for zip files inside another zip file. Can anyone suggest a way to do this? You have come across this before.

The fragment will look as follows.

private void checkZIP(ZipInputStream zInpStream, ZipFile zf) {
  try {  
    ZipEntry zipEntry = zInpStream.getNextEntry();
    while (zipEntry != null) {
       String entryName = zipEntry.getName();

       if(entryName.endsWith(".zip"))
          checkZIP(new ZipInputStream(zf.getInputStream(zipEntry)),<NEW ZIPFILE OBJECT FOR THIS ENTRY>);


       //other files parsing apart from zip.

       zInpStream.closeEntry();
       zipEntry = zInpStream.getNextEntry();
    }
    zInpStream.close();
  } catch(Exception ioe) {
    //catching specific exceptions here. But did not want to put al
  } 
}

EDIT: zip , . XML , Document. , zipInputStream parse() DocumentBuilder, , . (ZipFile object).getInputStream(currentEntryForXML) DocumentBuilder parse().

+3
1

ZipFile zip . ? , zInpStream conttructor,

checkZIP(new ZipInputStream(zInpStream));

zInpStream.getNextEntry() zInpStream , getNextEntry().

. . , , . FilterInputStream, close() Entry() zipInputStream, .

public class ZipGuard extends java.io.FilterInputStream {
    public ZipGuard(ZipInputStream is) {
        super(is);
    }

    @Override
    public void close() throws IOException {
        ((ZipInputStream) in).closeEntry();
    }
}

checkZip:

checkZip(new ZipInputStream(new ZipGuard(zInpStream)));
+4

Source: https://habr.com/ru/post/1718978/


All Articles