public 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()) {
addStatus(new WarnStatus("The target compressed file named ["
+ nameOfgzedFile + "] exist already.", this));
return;
}
try {
FileOutputStream fos = new FileOutputStream(nameOfgzedFile);
GZIPOutputStream gzos = new GZIPOutputStream(fos);
FileInputStream fis = new FileInputStream(nameOfFile2gz);
byte[] inbuf = new byte[8102];
int n;
while ((n = fis.read(inbuf)) != -1) {
gzos.write(inbuf, 0, n);
}
fis.close();
gzos.close();
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));