public class BufferedServletInputStream extends ServletInputStream
BufferedServletInputStream
wraps a
ServletInputStream
in order to provide input buffering and to
avoid calling the the readLine
method of the wrapped
ServletInputStream
.
This is necessary because some servlet containers rely on the default
implementation of the readLine
method provided by the Servlet
API classes, which is very slow. Tomcat 3.2, Tomcat 3.1, the JSWDK 1.0 web
server and the JSDK2.1 web server are all known to need this class for
performance reasons.
Also, it may be used to work around a bug in the Servlet API 2.0
implementation of readLine
which contains a bug that causes
ArrayIndexOutOfBoundsExceptions
under certain conditions.
Apache JServ is known to suffer from this bug.
Modifier and Type | Field and Description |
---|---|
private byte[] |
buf
our buffer
|
private int |
count
number of bytes we've read into the buffer
|
private ServletInputStream |
in
input stream we are filtering
|
private int |
pos
current position in the buffer
|
Constructor and Description |
---|
BufferedServletInputStream(ServletInputStream in)
Creates a
BufferedServletInputStream that wraps the provided
ServletInputStream . |
Modifier and Type | Method and Description |
---|---|
private void |
fill()
Fill up our buffer from the underlying input stream.
|
private static int |
findeol(byte[] b,
int pos,
int len)
Attempt to find the '\n' end of line marker as defined in the comment of
the
readLine method of ServletInputStream . |
int |
read()
Implement buffering on top of the
read method of
the wrapped ServletInputStream . |
int |
read(byte[] b,
int off,
int len)
Implement buffering on top of the
read method of
the wrapped ServletInputStream . |
int |
readLine(byte[] b,
int off,
int len)
Implement buffering on top of the
readLine method of
the wrapped ServletInputStream . |
available, close, mark, markSupported, read, reset, skip
private ServletInputStream in
private byte[] buf
private int count
private int pos
public BufferedServletInputStream(ServletInputStream in)
BufferedServletInputStream
that wraps the provided
ServletInputStream
.in
- a servlet input stream.private void fill() throws IOException
IOException
- if an I/O error occurs.public int readLine(byte[] b, int off, int len) throws IOException
readLine
method of
the wrapped ServletInputStream
.readLine
in class ServletInputStream
b
- an array of bytes into which data is read.off
- an integer specifying the character at which
this method begins reading.len
- an integer specifying the maximum number of
bytes to read.IOException
- if an I/O error occurs.private static int findeol(byte[] b, int pos, int len)
readLine
method of ServletInputStream
.b
- byte array to search.pos
- position in byte array to search from.len
- maximum number of bytes to search.public int read() throws IOException
read
method of
the wrapped ServletInputStream
.read
in class InputStream
-1
if the end of the
stream is reached.IOException
- if an I/O error occurs.public int read(byte[] b, int off, int len) throws IOException
read
method of
the wrapped ServletInputStream
.read
in class InputStream
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the maximum number of bytes read.-1
if there is no more data because the end
of the stream has been reached.IOException
- if an I/O error occurs.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses