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.
| Modifier and Type | Field and Description |
|---|---|
| private final TextStringBuilder | buffer
References Deprecated
Our internal buffer.
TextStringBuilder is deprecated or references (maybe indirectly) at least one deprecated element.
|
| private static final int | EOS
The end-of-stream character marker. |
| private boolean | eos
End-of-Stream flag. |
| private final StringMatcher | prefixEscapeMatcher
Matches escaped variable starts. |
| private final char[] | read1CharBuffer
Internal buffer for |
| private final StringSubstitutor | stringSubstitutor
The underlying StringSubstitutor. |
| private int | toDrain
We don't always want to drain the whole buffer. |
| Access | Constructor and Description |
|---|---|
| public | StringSubstitutorReader(final Reader
the underlying reader containing the template text known to the given reader, final StringSubstitutor StringSubstitutor.How to replace as we read. stringSubstitutor)Constructs a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| private int | |
| private int | bufferOrDrainOnEos(final int requestReadCount, final char[] target, final int targetIndex, final int targetLength)
Reads a requested number of chars from the underlying reader into the buffer. |
| private int | drain(final char[] target, final int targetIndex, final int targetLength)
Drains characters from our buffer to the given |
| private int | drainOnEos(final int readCountOrEos, final char[] target, final int targetIndex, final int targetLength)
Drains from the buffer to the target only if we are at EOS per the input count. |
| private boolean | isBufferMatchAt(final StringMatcher stringMatcher, final int pos)
Tests if our buffer matches the given string matcher at the given position in the buffer. |
| private boolean | |
| public int | Returns: a character as anint or -1 for end-of-stream.Overrides java. Reads a single character. |
| public int | Returns: The number of characters read, or -1 on end of stream.Target buffer. target, final int Index in the target at which to start storing characters. targetIndexIn, final int Maximum number of characters to read. targetLengthIn)Overrides java. Reads characters into a portion of an array. |
| private int | readCount(final int count, final int pos)
Returns how many chars to attempt reading to have room in the buffer for |
| buffer | back to summary |
|---|---|
| private final TextStringBuilder buffer
References Deprecated
See corresponding docs for further information. Our internal buffer. | |
| EOS | back to summary |
|---|---|
| private static final int EOS The end-of-stream character marker. | |
| eos | back to summary |
|---|---|
| private boolean eos End-of-Stream flag. | |
| prefixEscapeMatcher | back to summary |
|---|---|
| private final StringMatcher prefixEscapeMatcher Matches escaped variable starts. | |
| read1CharBuffer | back to summary |
|---|---|
| private final char[] read1CharBuffer Internal buffer for | |
| stringSubstitutor | back to summary |
|---|---|
| private final StringSubstitutor stringSubstitutor The underlying StringSubstitutor. | |
| toDrain | back to summary |
|---|---|
| private int toDrain We don't always want to drain the whole buffer. | |
| StringSubstitutorReader | back to summary |
|---|---|
| public StringSubstitutorReader(final Reader reader, final StringSubstitutor stringSubstitutor) Constructs a new instance.
| |
| buffer | back to summary |
|---|---|
| private int buffer(final int requestReadCount) throws IOException Buffers the requested number of characters if available. | |
| bufferOrDrainOnEos | back to summary |
|---|---|
| private int bufferOrDrainOnEos(final int requestReadCount, final char[] target, final int targetIndex, final int targetLength) throws IOException Reads a requested number of chars from the underlying reader into the buffer. On EOS, set the state is DRAINING, drain, and return a drain count, otherwise, returns the actual read count. | |
| drain | back to summary |
|---|---|
| private int drain(final char[] target, final int targetIndex, final int targetLength) Drains characters from our buffer to the given | |
| drainOnEos | back to summary |
|---|---|
| private int drainOnEos(final int readCountOrEos, final char[] target, final int targetIndex, final int targetLength) Drains from the buffer to the target only if we are at EOS per the input count. If input count is EOS, drain and returns the drain count, otherwise return the input count. If draining, the state is set to DRAINING. | |
| isBufferMatchAt | back to summary |
|---|---|
| private boolean isBufferMatchAt(final StringMatcher stringMatcher, final int pos) Tests if our buffer matches the given string matcher at the given position in the buffer. | |
| isDraining | back to summary |
|---|---|
| private boolean isDraining() Tests if we are draining. | |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Reads a single character.
| |
| read | back to summary |
|---|---|
| public int read(final char[] target, final int targetIndexIn, final int targetLengthIn) throws IOException Overrides java. Reads characters into a portion of an array.
| |
| readCount | back to summary |
|---|---|
| private int readCount(final int count, final int pos) Returns how many chars to attempt reading to have room in the buffer for | |