All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oreilly.servlet.multipart.PartInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.io.FilterInputStream
                   |
                   +----com.oreilly.servlet.multipart.PartInputStream

public class PartInputStream
extends FilterInputStream
A PartInputStream filters a ServletInputStream, providing access to a single MIME part contained with in which ends with the boundary specified. It uses buffering to provide maximum performance.

Note the readLine method of ServletInputStream has the annoying habit of adding a \r\n to the end of the last line. Since we want a byte-for-byte transfer, we have to cut those chars. This means that we must always maintain at least 2 characters in our buffer to allow us to trim when necessary.

Version:
1.1, 2000/11/26, fixed available() to never return negative
Author:
Geoff Soutter

Method Index

 o available()
Returns the number of bytes that can be read from this input stream without blocking.
 o close()
Closes this input stream and releases any system resources associated with the stream.
 o read()
See the general contract of the read method of InputStream.
 o read(byte[], int, int)
See the general contract of the read method of InputStream.

Methods

 o read
 public int read() throws IOException
See the general contract of the read method of InputStream.

Returns -1 (end of file) when the MIME boundary of this part is encountered.

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 FilterInputStream
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
See the general contract of the read method of InputStream.

Returns -1 (end of file) when the MIME boundary of this part is encountered.

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 FilterInputStream
 o available
 public int available() throws IOException
Returns the number of bytes that can be read from this input stream without blocking. This is a standard InputStream idiom to deal with buffering gracefully, and is not same as the length of the part arriving in this stream.

Returns:
the number of bytes that can be read from the input stream without blocking.
Throws: IOException
if an I/O error occurs.
Overrides:
available in class FilterInputStream
 o close
 public void close() throws IOException
Closes this input stream and releases any system resources associated with the stream.

This method will read any unread data in the MIME part so that the next part starts an an expected place in the parent InputStream. Note that if the client code forgets to call this method on error, MultipartParser will call it automatically if you call readNextPart().

Throws: IOException
if an I/O error occurs.
Overrides:
close in class FilterInputStream

All Packages  Class Hierarchy  This Package  Previous  Next  Index