Package skyview.request
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 Summary
Constructors Constructor Description TextReplacer(Map<String,String> fields, Reader input)
Create an object where we'll filter an input stream replacing variables with values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static void
main(String[] args)
Usage: TextReplacer filename key=val [key=val] ...int
read()
int
read(char[] buf)
int
read(char[] buf, int offset, int len)
String
readLine()
boolean
ready()
String
replace(String input)
Replace all settings variables with their values.long
skip(long val)
-
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, reset, transferTo
-
-
-
-
Constructor Detail
-
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 Detail
-
readLine
public String readLine() throws IOException
- Throws:
IOException
-
ready
public boolean ready() throws IOException
- Overrides:
ready
in classReader
- Throws:
IOException
-
read
public int read() throws IOException
- Overrides:
read
in classReader
- Throws:
IOException
-
skip
public long skip(long val) throws IOException
- Overrides:
skip
in classReader
- Throws:
IOException
-
read
public int read(char[] buf) throws IOException
- Overrides:
read
in classReader
- Throws:
IOException
-
read
public int read(char[] buf, int offset, int len) throws IOException
- Specified by:
read
in classReader
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
-