| java.lang.Object java.io.InputStream java.io.FilterInputStream net.matuschek.util.ChunkedInputStream
ChunkedInputStream | public class ChunkedInputStream extends FilterInputStream (Code) | | 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.
author: Jef Poskanzer author: Daniel Matuschek version: $Id: ChunkedInputStream.java,v 1.6 2002/05/31 14:45:56 matuschd Exp $ |
Method Summary | |
public int | getContentLength() Returns the size of the request entity data, or -1 if not known. | public String | getFooter(String name) Returns the value of a footer field, or null if not known. | public Enumeration | getFooters() Returns an Enumeration of the footer names. | public boolean | isDone() Tells whether the stream has gotten to its end yet. | public int | read() The FilterInputStream implementation of the single-byte read()
method just reads directly from the underlying stream. | public int | read(byte[] b, int off, int len) Reads into an array of bytes. | protected String | readLine() ChunkedInputStream used DataInputStream.readLine() before. |
ChunkedInputStream | public ChunkedInputStream(InputStream in)(Code) | | Make a ChunkedInputStream.
|
getContentLength | public int getContentLength()(Code) | | Returns the size of the request entity data, or -1 if not known.
|
getFooter | public String getFooter(String name)(Code) | | 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 |
getFooters | public Enumeration getFooters()(Code) | | Returns an Enumeration of the footer names.
|
isDone | public boolean isDone()(Code) | | 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.
|
read | public int read() throws IOException(Code) | | 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.
|
read | public int read(byte[] b, int off, int len) throws IOException(Code) | | Reads into an array of bytes.
Parameters: b - the buffer into which the data is read Parameters: off - the start offset of the data Parameters: len - the maximum number of bytes read the actual number of bytes read, or -1 on EOF exception: IOException - if an I/O error has occurred |
readLine | protected String readLine() throws IOException(Code) | | ChunkedInputStream used DataInputStream.readLine() before. This method
is deprecated, therefore we will it replace by our own method.
Because the chunk lines only use 7bit ASCII, we can use the
system default encoding
The data lines itself will not be read using this readLine method
but by a block read
|
|
|