1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.util;
19
20 import java.io.BufferedReader;
21 import java.io.FileNotFoundException;
22 import java.io.FileOutputStream;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.io.PrintStream;
26
27 public class Transformer {
28
29 public
30 static
31 void transform(String in, String out, Filter[] filters) throws FileNotFoundException,
32 IOException,
33 UnexpectedFormatException {
34
35 String line;
36 BufferedReader input = new BufferedReader(new FileReader(in));
37 PrintStream output = new PrintStream(new FileOutputStream(out, false));
38
39 try {
40
41 while ((line = input.readLine()) != null) {
42
43 for (int i = 0; i < filters.length; i++) {
44 line = filters[i].filter(line);
45 }
46 if (line != null) {
47 output.println(line);
48 }
49 }
50 } finally {
51 input.close();
52 output.close();
53 }
54 }
55
56
57
58 public
59 static
60 void transform(String in, String out, Filter filter) throws FileNotFoundException,
61 IOException,
62 UnexpectedFormatException {
63
64 String line;
65 BufferedReader input = new BufferedReader(new FileReader(in));
66 PrintStream output = new PrintStream(new FileOutputStream(out));
67
68 try {
69
70 while((line = input.readLine()) != null) {
71 line = filter.filter(line);
72 output.println(line);
73 }
74 } finally {
75 input.close();
76 output.close();
77 }
78 }
79
80 }