1 package net.sourceforge.cruisecontrol.logmanipulators; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import java.util.zip.GZIPOutputStream ; 8 9 public class GZIPManipulator extends BaseManipulator { 10 11 public void execute(String logDir) { 12 File [] filesToGZip = getRelevantFiles(logDir, false); 13 for (int i = 0; i < filesToGZip.length; i++) { 14 File file = filesToGZip[i]; 15 gzipFile(file, logDir); 16 } 17 } 18 19 private void gzipFile(File logfile, String logDir) { 20 try { 21 String fileName = logfile.getName() + ".gz"; 22 23 GZIPOutputStream out = new GZIPOutputStream ( 24 new FileOutputStream (new File (logDir, fileName))); 25 FileInputStream in = new FileInputStream (logfile); 26 int len; 27 while ((len = in.read()) > 0) { 28 out.write(len); 29 } 30 in.close(); 31 out.flush(); 32 out.close(); 33 logfile.delete(); 34 } catch (IOException e) { 35 e.printStackTrace(); 36 } 37 } 38 39 } 40 | Popular Tags |