I am using the below code to extract the files from zip archive.
public static List<String> unzipFiles(File zipFile, File targetDirectory) {
List<String> files = new ArrayList<String>();
BufferedOutputStream dest = null;
FileInputStream fileInputStream = null;
ZipInputStream zipInputStream = null;
try {
fileInputStream = new FileInputStream(zipFile);
zipInputStream = new ZipInputStream(new BufferedInputStream(
fileInputStream));
ZipEntry zipEntry;
int count = 0;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
log.debug("Extracting File Name :: " + zipEntry);
count++;
int length;
byte data[] = new byte[bufferGlb];
String fileName = zipEntry.getName();
File opFile = new File(targetDirectory, fileName);
FileOutputStream fileOutputStream = new FileOutputStream(opFile);
dest = new BufferedOutputStream(fileOutputStream, bufferGlb);
while ((length = zipInputStream.read(data, 0, bufferGlb)) != -1) {
dest.write(data, 0, length);
}
dest.flush();
files.add(fileName);
fileOutputStream.close();
}
log.debug("Total " + count + " Files Unziped Successfully ");
} catch (Exception e) {
log.error("Error occured in unzipping the file " + zipFile, e);
}
}
This code works fine with normal zip archives but not with zip64 archive. As far as I know that Java7/Java8 (ZipInputStream class) should support zip64 but am getting the below exception .
java.util.zip.ZipException: invalid entry size (expected 0 but got 21504 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:384)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:196)
However am able to extract files from zip64 using the commons-compress ZipArchiveInputStream.
Any idea why the same can't be achieved using the Java API (ZipInputStream).