Class Replacer

java.lang.Object
se.datadosen.util.Replacer

public class Replacer
extends java.lang.Object
Multiple string search and replace utility. This class accepts any number of search+replace string pairs to be added. It can then operate on either an input String or stream and replace all occurances of any search pattern with its corresponding replace string.

Example that does html > and < encoding:

 Replacer htmlEscaper = new Replacer();
 htmlEscaper.add("<", "&lt;");
 htmlEscaper.add(">", "&gt;");
 String escapedString = replacer.replace(aHtmlString);
 
  • Constructor Summary

    Constructors 
    Constructor Description
    Replacer()  
  • Method Summary

    Modifier and Type Method Description
    void add​(java.lang.String search, java.lang.String replace)  
    void processStreams​(java.io.Reader in2, java.io.Writer out2)  
    java.lang.String replace​(java.lang.String s)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • add

      public void add​(java.lang.String search, java.lang.String replace)
    • processStreams

      public void processStreams​(java.io.Reader in2, java.io.Writer out2) throws java.io.IOException
      Throws:
      java.io.IOException
    • replace

      public java.lang.String replace​(java.lang.String s)