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:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class StringSubstitutorReader extends java.io.FilterReaderAReaderthat performs string substitution on a sourceReaderusing aStringSubstitutor.Using this Reader avoids reading a whole file into memory as a
Stringto perform string substitution, for example, when a Servlet filters a file to a client.This class is not thread-safe.
- Since:
- 1.9
-
-
Constructor Summary
Constructors Constructor Description StringSubstitutorReader(java.io.Reader reader, StringSubstitutor stringSubstitutor)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread()Reads a single character.intread(char[] target, int targetIndexIn, int targetLengthIn)Reads characters into a portion of an array.
-
-
-
Constructor Detail
-
StringSubstitutorReader
public StringSubstitutorReader(java.io.Reader reader, StringSubstitutor stringSubstitutor)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:
java.lang.NullPointerException- ifreaderisnull.java.lang.NullPointerException- ifstringSubstitutorisnull.
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionReads a single character.- Overrides:
readin classjava.io.FilterReader- Returns:
- a character as an
intor-1for end-of-stream. - Throws:
java.io.IOException- If an I/O error occurs
-
read
public int read(char[] target, int targetIndexIn, int targetLengthIn) throws java.io.IOExceptionReads characters into a portion of an array.- Overrides:
readin classjava.io.FilterReader- 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:
java.io.IOException- If an I/O error occurs
-
-