All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oreilly.servlet.multipart.LimitedServletInputStream

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

public class LimitedServletInputStream
extends ServletInputStream
A LimitedServletInputStream wraps another ServletInputStream in order to keep track of how many bytes have been read and detect when the Content-Length limit has been reached. This is necessary since some servlet containers are slow to notice the end of stream and cause the client code to hang if it tries to read past it.

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

Constructor Index

 o LimitedServletInputStream(ServletInputStream, int)
Creates a LimitedServletInputStream with the specified length limit that wraps the provided ServletInputStream.

Method Index

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

Constructors

 o LimitedServletInputStream
 public LimitedServletInputStream(ServletInputStream in,
                                  int totalExpected)
Creates a LimitedServletInputStream with the specified length limit that wraps the provided ServletInputStream.

Methods

 o readLine
 public int readLine(byte b[],
                     int off,
                     int len) throws IOException
Implement length limitation 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 length limitation 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 length limitation on top of the read method of the wrapped ServletInputStream.

Parameters:
b - destination buffer.
off - offset at which to start storing bytes.
len - maximum number of bytes to read.
Returns:
the number of bytes read, or -1 if 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