All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oreilly.servlet.multipart.BufferedServletInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----javax.servlet.ServletInputStream
                   |
                   +----com.oreilly.servlet.multipart.BufferedServletInputStream

public class BufferedServletInputStream
extends ServletInputStream
A 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.

Version:
1.0, 2000/10/27, initial revision
Author:
Geoff Soutter

Constructor Index

 o BufferedServletInputStream(ServletInputStream)
Creates a BufferedServletInputStream that wraps the provided ServletInputStream.

Method Index

 o read()
Implement buffering on top of the read method of the wrapped ServletInputStream.
 o read(byte[], int, int)
Implement buffering on top of the read method of the wrapped ServletInputStream.
 o readLine(byte[], int, int)
Implement buffering on top of the readLine method of the wrapped ServletInputStream.

Constructors

 o BufferedServletInputStream
 public BufferedServletInputStream(ServletInputStream in)
Creates a BufferedServletInputStream that wraps the provided ServletInputStream.

Parameters:
in - a servlet input stream.

Methods

 o readLine
 public int readLine(byte b[],
                     int off,
                     int len) throws IOException
Implement buffering on top of the readLine method of the wrapped ServletInputStream.

Parameters:
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.
Returns:
an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached.
Throws: IOException
if an I/O error occurs.
Overrides:
readLine in class ServletInputStream
 o read
 public int read() throws IOException
Implement buffering on top of the read method of the wrapped ServletInputStream.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws: IOException
if an I/O error occurs.
Overrides:
read in class InputStream
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Implement buffering on top of the read method of the wrapped ServletInputStream.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws: IOException
if an I/O error occurs.
Overrides:
read in class InputStream

All Packages  Class Hierarchy  This Package  Previous  Next  Index