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 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      // Initialization of input and output omitted
39      while((line = input.readLine()) != null) {
40        // apply all filters
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      // Initialization of input and output omitted
62      while((line = input.readLine()) != null) {
63        line = filter.filter(line);
64        output.println(line);
65      }
66    }
67  
68  }