Class TextReplacer

java.lang.Object
java.io.Reader
skyview.request.TextReplacer
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class TextReplacer extends Reader
This class provides a utility function that transforms strings to replace embedded settings with the current values of the setting.
  • Constructor Details

    • TextReplacer

      public TextReplacer(Map<String,String> fields, Reader input) throws IOException
      Create an object where we'll filter an input stream replacing variables with values.
      Parameters:
      fields - The map from variable keys to output values.
      input - The input Reader to be filtered.
      Throws:
      IOException
  • Method Details

    • readLine

      public String readLine() throws IOException
      Throws:
      IOException
    • ready

      public boolean ready() throws IOException
      Overrides:
      ready in class Reader
      Throws:
      IOException
    • read

      public int read() throws IOException
      Overrides:
      read in class Reader
      Throws:
      IOException
    • skip

      public long skip(long val) throws IOException
      Overrides:
      skip in class Reader
      Throws:
      IOException
    • read

      public int read(char[] buf) throws IOException
      Overrides:
      read in class Reader
      Throws:
      IOException
    • read

      public int read(char[] buf, int offset, int len) throws IOException
      Specified by:
      read in class Reader
      Throws:
      IOException
    • replace

      public String replace(String input)
      Replace all settings variables with their values. This function takes the current line and looks for all variables that are embedded in the string and replaces those variables with their value. E.g., given a string "The survey is ${survey} and the scale is ${scale}." the method will replace the string ${survey} with the specified value of survey and ${scale} with the specified value of scale. If an unmatched variable is found, the entire line is returned as a "". This allows one to control which lines are returned by the presence or absence of variables.
    • main

      public static void main(String[] args) throws Exception
      Usage: TextReplacer filename key=val [key=val] ...
      Throws:
      Exception
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      Throws:
      IOException