View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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        // Initialization of input and output omitted
41        while ((line = input.readLine()) != null) {
42          // apply all filters
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        // Initialization of input and output omitted
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  }