private void zipCompress(String nameOfFile2zip, String nameOfZippedFile, String innerEntryName) {
File file2zip = new File(nameOfFile2zip);
if (!file2zip.exists()) {
addStatus(new WarnStatus("The file to compress named [" + nameOfFile2zip
+ "] does not exist.", this));
return;
}
if(innerEntryName == null) {
addStatus(new WarnStatus("The innerEntryName parameter cannot be null", this));
return;
}
if (!nameOfZippedFile.endsWith(".zip")) {
nameOfZippedFile = nameOfZippedFile + ".zip";
}
File zippedFile = new File(nameOfZippedFile);
if (zippedFile.exists()) {
addStatus(new WarnStatus("The target compressed file named ["
+ nameOfZippedFile + "] exist already.", this));
return;
}
try {
FileOutputStream fos = new FileOutputStream(nameOfZippedFile);
ZipOutputStream zos = new ZipOutputStream(fos);
FileInputStream fis = new FileInputStream(nameOfFile2zip);
ZipEntry zipEntry = computeZipEntry(innerEntryName);
zos.putNextEntry(zipEntry);
byte[] inbuf = new byte[8102];
int n;
while ((n = fis.read(inbuf)) != -1) {
zos.write(inbuf, 0, n);
}
fis.close();
zos.close();
if (!file2zip.delete()) {
addStatus(new WarnStatus("Could not delete [" + nameOfFile2zip + "].",
this));
}
} catch (Exception e) {
addStatus(new ErrorStatus("Error occurred while compressing ["
+ nameOfFile2zip + "] into [" + nameOfZippedFile + "].", this, e));