|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
de.fhg.igd.io.VariableSubstitutionInputStream
public class VariableSubstitutionInputStream
This class wrappes an InputStream
and provides
substitution of variables while reading from it. Variables
to be substituted have to be embraced by braces and preceded
by a dollar sign (${variable}
). A simple
$
without following opening brace is forwarded
as is. The leading backslash in \${
escapes
the dollar sign. Hence, this character sequence is forwarded
as single dollar sign without forcing any variable substition,
too.
The variables to be substituted are given as name/value-Map
.
Field Summary | |
---|---|
private PushbackInputStream |
pis_
The wrapper for the given input stream. |
private SortedMap |
variables_
Internal map which stores the variables to substitute as key/value-pairs (both of type String). |
Constructor Summary | |
---|---|
VariableSubstitutionInputStream(InputStream is,
Map variables)
Creates a VariableSubstitutionInputStream
which wrappes the given InputStream . |
Method Summary | |
---|---|
int |
available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
void |
close()
Closes the wrapped input stream and releases any system resources associated with the stream. |
private void |
init(InputStream is,
Map variables)
Initializes the class instance. |
private byte[] |
lookup(String key)
Looks up the given variable. |
static void |
main(String[] argv)
Just for testing purpose. |
int |
read()
Reads the next byte of data from the input stream. |
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, read, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private PushbackInputStream pis_
private SortedMap variables_
Constructor Detail |
---|
public VariableSubstitutionInputStream(InputStream is, Map variables)
VariableSubstitutionInputStream
which wrappes the given InputStream
.
is
- the InputStream
to be wrapped.variables
- the name/value Map
used for
variable substitution.Method Detail |
---|
private void init(InputStream is, Map variables)
private byte[] lookup(String key)
public int read() throws IOException
int
in the range 0
to
255
. If no byte is available because the end of the stream
has been reached, the value -1
is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.
A subclass must provide an implementation of this method.
read
in class InputStream
-1
if the end of the
stream is reached.
IOException
- if an I/O error occurs.public int available() throws IOException
Since the number of bytes available can not be determined in advance
the available
method for this class always returns 0
.
available
in class InputStream
IOException
- if an I/O error occurs.public void close() throws IOException
The close
method of InputStream
does
nothing.
close
in interface Closeable
close
in class InputStream
IOException
- if an I/O error occurs.public static void main(String[] argv)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |