All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Acme.Serve.servlet.http.ChunkedInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.io.FilterInputStream
                   |
                   +----Acme.Serve.servlet.http.ChunkedInputStream

public class ChunkedInputStream
extends FilterInputStream
An InputStream that implements HTTP/1.1 chunking.

This class lets a Servlet read its request data as an HTTP/1.1 chunked stream. Chunked streams are a way to send arbitrary-length data without having to know beforehand how much you're going to send. They are introduced by a "Transfer-Encoding: chunked" header, so if such a header appears in an HTTP request you should use this class to read any data.

Sample usage:


 InputStream in = req.getInputStream();
 if ( "chunked".equals( req.getHeader( "Transfer-Encoding" ) ) )
     in = new ChunkedInputStream( in );
 

Because it would be impolite to make the authors of every Servlet include the above code, this is general done at the server level so that it happens automatically. Servlet authors will generally not create ChunkedInputStreams. This is in contrast with ChunkedOutputStream, which Servlets have to call themselves if they want to use it.

Fetch the software.
Fetch the entire Acme package.


Constructor Index

 o ChunkedInputStream(InputStream)
Make a ChunkedInputStream.

Method Index

 o getContentLength()
Returns the size of the request entity data, or -1 if not known.
 o getFooter(String)
Returns the value of a footer field, or null if not known.
 o getFooters()
Returns an Enumeration of the footer names.
 o isDone()
Tells whether the stream has gotten to its end yet.
 o read()
The FilterInputStream implementation of the single-byte read() method just reads directly from the underlying stream.
 o read(byte[], int, int)
Reads into an array of bytes.

Constructors

 o ChunkedInputStream
 public ChunkedInputStream(InputStream in)
Make a ChunkedInputStream.

Methods

 o read
 public int read() throws IOException
The FilterInputStream implementation of the single-byte read() method just reads directly from the underlying stream. We want to go through our own read-block method, so we have to override. Seems like FilterInputStream really ought to do this itself.

Overrides:
read in class FilterInputStream
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Reads into an array of bytes.

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 actual number of bytes read, or -1 on EOF
Throws: IOException
if an I/O error has occurred
Overrides:
read in class FilterInputStream
 o getFooter
 public String getFooter(String name)
Returns the value of a footer field, or null if not known. Footers come at the end of a chunked stream, so trying to retrieve them before the stream has given an EOF will return only nulls.

Parameters:
name - the footer field name
 o getFooters
 public Enumeration getFooters()
Returns an Enumeration of the footer names.

 o getContentLength
 public int getContentLength()
Returns the size of the request entity data, or -1 if not known.

 o isDone
 public boolean isDone()
Tells whether the stream has gotten to its end yet. Remembering whether you've gotten an EOF works fine too, but this is a convenient predicate. java.io.InputStream should probably have its own isEof() predicate.


All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs