I am uploading a zip file (heap dump) in a request through postman tool and retrieving file content in servlet using request.getInputStream()
method.
I have an InputStream that contains zipped bits and would like to decompress that using a ZipInputStream. I did not see any way to currently do this using Zip4j. Currently, the only way to create a ZipInputStream is from a ZipFile which needs to be from a File and not an InputStream. I am looking for something that works similar to the way that java.util.zip.ZipInputStream works.
I have tried java.util.zip.ZipInputStream
but getNextEntry()
method is returning NULL sometimes. Find my code below,
ZipInputStream zis = new ZipInputStream(request.getInputStream());
ZipEntry ze = zis.getNextEntry();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
while(ze!=null) {
int len;
while((len = zis.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
ze = zis.getNextEntry();
}
out.close();
zis.close();
return out.toByteArray();
Is there any way to achieve this using the zip4j library?
Thanks in advance!