KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > logmanipulators > GZIPManipulator


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