Hello All,
I have a zip file which can contain any number of zipfiles inside it (recursively also). I need to iterate over all of them.
Right now, i have a function which takes zipInputStream and zipFile as parameters. The problem is; if i get a zip inside another zip, i am calling this function recursively again. So i dont know how to create a zipFile object for zipfiles inside another zipfile. Can someone suggest a way to do it? Have you come across this before.
The snippet will look like this.
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: I need that zip file object because. If i come across an XML file, i need to create a Document object. So if i pass the normal zipInputStream for parse()
method in DocumentBuilder
, it closes the stream and i am not able to use it again. So i used (ZipFile object).getInputStream(currentEntryForXML)
inside DocumentBuilder parse().