Package org.codehaus.plexus.util
Class LineOrientedInterpolatingReader
java.lang.Object
java.io.Reader
java.io.FilterReader
org.codehaus.plexus.util.LineOrientedInterpolatingReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
A FilterReader which interpolates keyword values into a character stream. Keywords are recognized when enclosed
between starting and ending delimiter strings. The keywords themselves, and their values, are fetched from a Map
supplied to the constructor.
When a possible keyword token is recognized (by detecting the starting and ending token delimiters):
- if the enclosed string is found in the keyword Map, the delimiters and the keyword are effectively replaced by the keyword's value;
- if the enclosed string is found in the keyword Map, but its value has zero length, then the token (delimiters and keyword) is effectively removed from the character stream;
- if the enclosed string is not found in the keyword Map, then no substitution is made; the token text is passed through unaltered.
A token in the incoming character stream may be escaped by prepending an "escape sequence" which is specified to the constructor. An escaped token is passed through as written, with the escape sequence removed. This allows things which would look like tokens to be read literally rather than interpolated.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char
static final String
static final String
static final String
private final String
private final String
private String
private int
private final int
private static final char
private final PushbackReader
private final Reflector
private final String
Fields inherited from class java.io.FilterReader
in
-
Constructor Summary
ConstructorsConstructorDescriptionLineOrientedInterpolatingReader
(Reader reader, Map<String, ?> context) Filters a Reader using the default escape sequence "\" and token delimiters "${", "}".LineOrientedInterpolatingReader
(Reader reader, Map<String, ?> context, String startDelim, String endDelim) Filters a Reader using the default escape sequence "\".LineOrientedInterpolatingReader
(Reader reader, Map<String, ?> context, String startDelim, String endDelim, String escapeSeq) Construct an interpolating Reader, specifying token delimiters and the escape sequence. -
Method Summary
Modifier and TypeMethodDescriptionevaluateExpressions
(Set<String> expressions) private String
findAndReplaceUnlessEscaped
(String rawLine, String search, String replace) private int
findDelimiter
(String rawLine, String delimiter, int lastPos) parseForExpressions
(String rawLine) int
read()
int
read
(char[] cbuf, int off, int len) private void
private String
readLine()
private String
replaceWithInterpolatedValues
(String rawLine, Map<String, Object> evaluatedExpressions) long
skip
(long n) Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset
-
Field Details
-
DEFAULT_START_DELIM
- See Also:
-
DEFAULT_END_DELIM
- See Also:
-
DEFAULT_ESCAPE_SEQ
- See Also:
-
CARRIAGE_RETURN_CHAR
private static final char CARRIAGE_RETURN_CHAR- See Also:
-
NEWLINE_CHAR
private static final char NEWLINE_CHAR- See Also:
-
pushbackReader
-
context
-
startDelim
-
endDelim
-
escapeSeq
-
minExpressionSize
private final int minExpressionSize -
reflector
-
lineIdx
private int lineIdx -
line
-
-
Constructor Details
-
LineOrientedInterpolatingReader
public LineOrientedInterpolatingReader(Reader reader, Map<String, ?> context, String startDelim, String endDelim, String escapeSeq) Construct an interpolating Reader, specifying token delimiters and the escape sequence.- Parameters:
reader
- the Reader to be filtered.context
- keyword/value pairs for interpolation.startDelim
- character sequence which (possibly) begins a token.endDelim
- character sequence which ends a token.escapeSeq
- escape sequence
-
LineOrientedInterpolatingReader
public LineOrientedInterpolatingReader(Reader reader, Map<String, ?> context, String startDelim, String endDelim) Filters a Reader using the default escape sequence "\".- Parameters:
reader
- the Reader to be filtered.context
- keyword/value pairs for interpolation.startDelim
- the character sequence which (possibly) begins a token.endDelim
- the character sequence which ends a token.
-
LineOrientedInterpolatingReader
Filters a Reader using the default escape sequence "\" and token delimiters "${", "}".- Parameters:
reader
- the Reader to be filtered.context
- keyword/value pairs for interpolation.
-
-
Method Details
-
read
- Overrides:
read
in classFilterReader
- Throws:
IOException
-
read
- Overrides:
read
in classFilterReader
- Throws:
IOException
-
skip
- Overrides:
skip
in classFilterReader
- Throws:
IOException
-
readAndInterpolateLine
- Throws:
IOException
-
readLine
- Throws:
IOException
-
replaceWithInterpolatedValues
-
evaluateExpressions
-
parseForExpressions
-
findDelimiter
-
findAndReplaceUnlessEscaped
-