public class EspReader
extends java.io.FilterReader
EspReader
is a FilterReader
which takes
JSP like input and produces plain ECMA script output. The filtering
modifications done on the input comprise the following :
The nice thing about this reader is, that the line numbers of the resulting stream match the line numbers of the matching contents of the input stream. Due to the insertion of write() calls, column numbers will not necessarily match, though. This is especially true if you mix ECMA code tags (<% %>) with template text on the same line.
For maximum performance it is advisable to not create the EspReader with a plain FileReader or InputStreamReader but rather with a BufferedReader based on one of the simpler Readers. The reasons for this is, that we call the base reader character by character. This in turn is not too performing if the base reader does not buffer its input.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_OUT_INIT_STATEMENT
Javascript statement that sets the "out" variable that's used
to output data.
|
Constructor and Description |
---|
EspReader(java.io.Reader baseReader)
Create an EspReader on top of the given
baseReader . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the EspReader.
|
void |
mark(int readAheadLimit)
Mark the present position in the stream.
|
boolean |
markSupported()
Tell whether this stream supports the mark() operation, which it does
not.
|
int |
read()
Return the next filtered character.
|
int |
read(char[] cbuf)
Fill the given buffer with filtered or injected characters.
|
int |
read(char[] cbuf,
int off,
int len)
Fill the buffer from the offset with the number of characters given.
|
boolean |
ready()
Check whether we may block at the next read() operation.
|
void |
reset()
Reset the stream.
|
void |
setOutInitStatement(java.lang.String statement)
Set the code fragment used to initialize the "out" variable
|
long |
skip(long n)
Skip the number of filtered characters.
|
public static final java.lang.String DEFAULT_OUT_INIT_STATEMENT
public EspReader(java.io.Reader baseReader)
baseReader
. The
constructor wraps the input reader with a PushbackReader
,
so that input stream modifications may be handled transparently by our
doRead()
method.baseReader
- the wrapped readerpublic void setOutInitStatement(java.lang.String statement)
statement
- the statement used for initializationpublic boolean ready() throws java.io.IOException
ready
in class java.io.FilterReader
true
if a character is available on the
PushbackReader
.java.io.IOException
- if the reader is not openpublic int read() throws java.io.IOException
read
in class java.io.FilterReader
java.io.IOException
- if the reader is not openpublic int read(char[] cbuf) throws java.io.IOException
read(cbuf, 0, cbuf.length)
.read
in class java.io.Reader
cbuf
- The character buffer to fill with (filtered) charactersjava.io.IOException
- if the reader is not openpublic int read(char[] cbuf, int off, int len) throws java.io.IOException
read
in class java.io.FilterReader
cbuf
- The character buffer to fill with (filtered) charactersoff
- Offset from where to start in the bufferlen
- The number of characters to fill into the bufferjava.io.IOException
- if the reader is not openjava.lang.IndexOutOfBoundsException
- if len is negative, off is negative or
higher than the buffer length or off+len is negative or
beyond the buffer size.public long skip(long n) throws java.io.IOException
skip
in class java.io.FilterReader
n
- the number of (filtered) characters to skipjava.lang.IllegalArgumentException
- if n is negativejava.io.IOException
- if the reading the characters throwspublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.FilterReader
java.io.IOException
public void mark(int readAheadLimit) throws java.io.IOException
mark
for
class EspReader
always throws an throwable.mark
in class java.io.FilterReader
readAheadLimit
- The number of characters to read aheadjava.io.IOException
- Always, since mark is not supportedpublic boolean markSupported()
markSupported
in class java.io.FilterReader
public void reset() throws java.io.IOException
reset
method of
EspReader
always throws an throwable.reset
in class java.io.FilterReader
java.io.IOException
- Always, since reset is not supportedCopyright © 2018 The Apache Software Foundation. All rights reserved.