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 IOException,
32 UnexpectedFormatException {
33
34 String line;
35 BufferedReader input = new BufferedReader(new FileReader(in));
36 PrintStream output = new PrintStream(new FileOutputStream(out, false));
37
38
39 while((line = input.readLine()) != null) {
40
41 for(int i = 0; i < filters.length; i++) {
42 line = filters[i].filter(line);
43 }
44 if(line != null) {
45 output.println(line);
46 }
47 }
48 }
49
50
51
52 public
53 static
54 void transform(String in, String out, Filter filter) throws IOException,
55 UnexpectedFormatException {
56
57 String line;
58 BufferedReader input = new BufferedReader(new FileReader(in));
59 PrintStream output = new PrintStream(new FileOutputStream(out));
60
61
62 while((line = input.readLine()) != null) {
63 line = filter.filter(line);
64 output.println(line);
65 }
66 }
67
68 }