private void gzCompress(String nameOfFile2gz, String nameOfgzedFile) {
File file2gz = new File(nameOfFile2gz);
if (!file2gz.exists()) {
addStatus(new WarnStatus("The file to compress named [" + nameOfFile2gz
+ "] does not exist.", this));
return;
}
if (!nameOfgzedFile.endsWith(".gz")) {
nameOfgzedFile = nameOfgzedFile + ".gz";
}
File gzedFile = new File(nameOfgzedFile);
if (gzedFile.exists()) {
addWarn("The target compressed file named ["
+ nameOfgzedFile + "] exist already. Aborting file compression.");
return;
}
addInfo("GZ compressing [" + file2gz + "] as ["+gzedFile+"]");
createMissingTargetDirsIfNecessary(gzedFile);
BufferedInputStream bis = null;
GZIPOutputStream gzos = null;
try {
bis = new BufferedInputStream(new FileInputStream(nameOfFile2gz));
gzos = new GZIPOutputStream(new FileOutputStream(nameOfgzedFile));
byte[] inbuf = new byte[BUFFER_SIZE];
int n;
while ((n = bis.read(inbuf)) != -1) {
gzos.write(inbuf, 0, n);
}
bis.close();
bis = null;
gzos.close();
gzos = null;
if (!file2gz.delete()) {
addStatus(new WarnStatus("Could not delete [" + nameOfFile2gz + "].",
this));
}
} catch (Exception e) {
addStatus(new ErrorStatus("Error occurred while compressing ["
+ nameOfFile2gz + "] into [" + nameOfgzedFile + "].", this, e));