after calling
createZipFileFromFolder(source, parameters, true, splitSize)
the generated file name mismatch the physical name BUT only for the splited file number 10. So the name generated by the function getSplitZipFiles() will be 'filename.z010' while the real file name store is 'filename.z10'.
any idea why? and how to fix it
File outFile = new File(out_zip);
ZipFile zipFile = new ZipFile(out_zip);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.createZipFileFromFolder(source, parameters, true, splitSize);
splitZipFiles = zipFile.getSplitZipFiles();
Seems like a bug in 'zip4j'.
It's because of this logic in 'Zip4jUtil' class. For file number 9, the if condition fails, but fileExt is still '.z0' and adds +1 to the file name. Instead the condition should have been if(i>=9) to match the file creation logic.
for (int i = 0; i <= numberOfThisDisk; i++) {
if (i == numberOfThisDisk) {
retList.add(zipModel.getZipFile());
} else {
String fileExt = ".z0";
if (i > 9) {
fileExt = ".z";
}
partFile = (zipFileName.indexOf(".") >= 0) ? currZipFile.substring(0, currZipFile.lastIndexOf(".")) : currZipFile;
partFile = partFile + fileExt + (i + 1);
retList.add(partFile);
}
}
But while creating the actual split file in 'SplitOutputStream' class, the logic is fine to generate the proper file name. Below code will generate '.z10' file instead of '.z010'.
if (currSplitFileCounter < 9) {
currSplitFile = new File(parentPath + zipFileWithoutExt + ".z0" + (currSplitFileCounter + 1));
} else {
currSplitFile = new File(parentPath + zipFileWithoutExt + ".z" + (currSplitFileCounter + 1));
}
So file creation is fine, the problem is with the logic while listing the files.
1) Submit the bug report to the dev team, and meanwhile grab the source of 'zip4j
' from http://www.lingala.net/zip4j/download.php
.
2) Then change the logic if(i>9) to if(i>=9)
in 'Zip4jUtil.java
' @ line: 690. Create the binary .jar file and use it in your application.