View Javadoc

1   package cz.cuni.amis.utils;
2   
3   import java.io.BufferedReader;
4   import java.io.IOException;
5   import java.io.PrintWriter;
6   import java.util.Map;
7   
8   /**
9    * Very slow and very dumb string replacer ... do not use extensively!
10   * 
11   * @author Jimmy
12   */
13  public class StringReplacer {
14  	
15  	public static void replace(BufferedReader reader, PrintWriter writer, Map<String, String> replace) throws IOException {
16  		while(reader.ready()) {
17  			String line = reader.readLine();
18  			for(String key : replace.keySet()) {
19  				if (line.contains(key)) {
20  					line = line.replace(key, replace.get(key));
21  				}
22  			}
23  			writer.println(line);
24  		}
25  	}
26  
27  }