Package org.apache.commons.text.io
Class StringSubstitutorReader
java.lang.Object
java.io.Reader
java.io.FilterReader
org.apache.commons.text.io.StringSubstitutorReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
A
Reader that performs string substitution on a source Reader using a StringSubstitutor.
Using this Reader avoids reading a whole file into memory as a String to perform string substitution, for
example, when a Servlet filters a file to a client.
This class is not thread-safe.
- Since:
- 1.9
-
Field Summary
Fields inherited from class java.io.FilterReader
in -
Constructor Summary
ConstructorsConstructorDescriptionStringSubstitutorReader(Reader reader, StringSubstitutor stringSubstitutor) Constructs a new instance. -
Method Summary
Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset, skip
-
Constructor Details
-
StringSubstitutorReader
Constructs a new instance.- Parameters:
reader- the underlying reader containing the template text known to the givenStringSubstitutor.stringSubstitutor- How to replace as we read.- Throws:
NullPointerException- ifreaderisnull.NullPointerException- ifstringSubstitutorisnull.
-
-
Method Details
-
read
Reads a single character.- Overrides:
readin classFilterReader- Returns:
- a character as an
intor-1for end-of-stream. - Throws:
IOException- If an I/O error occurs
-
read
Reads characters into a portion of an array.- Overrides:
readin classFilterReader- Parameters:
target- Target buffer.targetIndexIn- Index in the target at which to start storing characters.targetLengthIn- Maximum number of characters to read.- Returns:
- The number of characters read, or -1 on end of stream.
- Throws:
IOException- If an I/O error occurs
-