Package skyview.request
Class TextReplacer
- java.lang.Object
-
- java.io.Reader
-
- skyview.request.TextReplacer
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class TextReplacer extends java.io.ReaderThis 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(java.util.Map<java.lang.String,java.lang.String> fields, java.io.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 voidclose()static voidmain(java.lang.String[] args)Usage: TextReplacer filename key=val [key=val] ...intread()intread(char[] buf)intread(char[] buf, int offset, int len)java.lang.StringreadLine()booleanready()java.lang.Stringreplace(java.lang.String input)Replace all settings variables with their values.longskip(long val)
-
-
-
Constructor Detail
-
TextReplacer
public TextReplacer(java.util.Map<java.lang.String,java.lang.String> fields, java.io.Reader input) throws java.io.IOExceptionCreate 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:
java.io.IOException
-
-
Method Detail
-
readLine
public java.lang.String readLine() throws java.io.IOException- Throws:
java.io.IOException
-
ready
public boolean ready() throws java.io.IOException- Overrides:
readyin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
skip
public long skip(long val) throws java.io.IOException- Overrides:
skipin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] buf) throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] buf, int offset, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
replace
public java.lang.String replace(java.lang.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(java.lang.String[] args) throws java.lang.ExceptionUsage: TextReplacer filename key=val [key=val] ...- Throws:
java.lang.Exception
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
-