Package skyview.request
Class TextReplacer
java.lang.Object
java.io.Reader
skyview.request.TextReplacer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
This class provides a utility function that transforms strings
to replace embedded settings with the current values of the setting.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTextReplacer
(Map<String, String> fields, Reader input) Create an object where we'll filter an input stream replacing variables with values. -
Method Summary
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, reset, transferTo
-
Constructor Details
-
TextReplacer
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
- Throws:
IOException
-
ready
- Overrides:
ready
in classReader
- Throws:
IOException
-
read
- Overrides:
read
in classReader
- Throws:
IOException
-
skip
- Overrides:
skip
in classReader
- Throws:
IOException
-
read
- Overrides:
read
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-
replace
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
Usage: TextReplacer filename key=val [key=val] ...- Throws:
Exception
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-