# Class StringSubstitutorReader

java.lang.Object
java.io.Reader
java.io.FilterReader
org.apache.commons.text.io.StringSubstitutorReader

All Implemented Interfaces:
  `Closeable, AutoCloseable, Readable`

public class StringSubstitutorReader extends FilterReader
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 FilterReader

  `in`

  ### Fields inherited from class Reader

  `lock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StringSubstitutorReader(Reader reader, StringSubstitutor stringSubstitutor)`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `read()`
  Reads a single character.
  `int`
  `read(char[] target, int targetIndexIn, int targetLengthIn)`
  Reads characters into a portion of an array.

  ### Methods inherited from class FilterReader

  `close, mark, markSupported, ready, reset, skip`

  ### Methods inherited from class Reader

  `read, read`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### StringSubstitutorReader

    public StringSubstitutorReader(Reader reader, StringSubstitutor stringSubstitutor)
    Constructs a new instance.
    Parameters:
      `reader` - the underlying reader containing the template text known to the given `StringSubstitutor`.
      `stringSubstitutor` - How to replace as we read.
    Throws:
      `NullPointerException` - if `reader` is `null`.
      `NullPointerException` - if `stringSubstitutor` is `null`.

- ## Method Details

  - ### read

    public int read() throws IOException
    Reads a single character.
    Overrides:
      `read` in class `FilterReader`
    Returns:
      a character as an `int` or `-1` for end-of-stream.
    Throws:
      `IOException` - If an I/O error occurs.

  - ### read

    public int read(char[] target, int targetIndexIn, int targetLengthIn) throws IOException
    Reads characters into a portion of an array.
    Overrides:
      `read` in class `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:
      `IOException` - If an I/O error occurs.