org.mortbay.http
Class HttpInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by org.mortbay.http.HttpInputStream
All Implemented Interfaces:
java.io.Closeable

public class HttpInputStream
extends java.io.FilterInputStream

HTTP Chunking InputStream. This FilterInputStream acts as a BufferedInputStream until setChunking(true) is called. Once chunking is enabled, the raw stream is chunk decoded as per RFC2616. The "8859-1" encoding is used on underlying LineInput instance for line based reads from the raw stream. This class is not synchronized and should be synchronized explicitly if an instance is used by multiple threads.

Version:
$Id: HttpInputStream.java,v 1.13 2005/08/23 20:02:26 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
LineInput

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
HttpInputStream(java.io.InputStream in)
          Constructor.
HttpInputStream(java.io.InputStream in, int bufferSize)
          Constructor.
 
Method Summary
 void close()
           
 void destroy()
           
 int getContentLength()
          Get the content length.
 java.io.OutputStream getExpectContinues()
           
 java.io.InputStream getFilterStream()
          Get Filter InputStream.
 java.io.InputStream getInputStream()
          Get the raw stream.
 HttpFields getTrailer()
           
 boolean isChunking()
          Get chunking mode
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void resetStream()
          Reset the stream.
 void setChunking()
          Set chunking mode.
 void setContentLength(int len)
          Set the content length.
 void setExpectContinues(java.io.OutputStream expectContinues)
           
 void setFilterStream(java.io.InputStream filter)
          Set Filter InputStream.
 long skip(long n)
           
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpInputStream

public HttpInputStream(java.io.InputStream in)
Constructor.


HttpInputStream

public HttpInputStream(java.io.InputStream in,
                       int bufferSize)
Constructor.

Method Detail

getExpectContinues

public java.io.OutputStream getExpectContinues()
Parameters:
expectContinues - The expectContinues to set.

setExpectContinues

public void setExpectContinues(java.io.OutputStream expectContinues)
Parameters:
expectContinues - The expectContinues to set.

read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Overrides:
skip in class java.io.FilterInputStream
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
Get the raw stream. A stream without filters or chunking is returned. This stream may still be buffered and uprocessed bytes may be in the buffer.

Returns:
Raw InputStream.

getFilterStream

public java.io.InputStream getFilterStream()
Get Filter InputStream. Get the current top of the InputStream filter stack

Returns:
InputStream.

setFilterStream

public void setFilterStream(java.io.InputStream filter)
Set Filter InputStream. Set input filter stream, which should be constructed to wrap the stream returned from get FilterStream.


isChunking

public boolean isChunking()
Get chunking mode


setChunking

public void setChunking()
                 throws java.lang.IllegalStateException
Set chunking mode. Chunking can only be turned off with a call to resetStream().

Throws:
java.lang.IllegalStateException - Checking cannot be set if a content length has been set.

resetStream

public void resetStream()
                 throws java.lang.IllegalStateException
Reset the stream. Turn chunking off and disable all filters.

Throws:
java.lang.IllegalStateException - The stream cannot be reset if there is some unread chunked input or a content length greater than zero remaining.

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException

setContentLength

public void setContentLength(int len)
Set the content length. Only this number of bytes can be read before EOF is returned.

Parameters:
len - length.

getContentLength

public int getContentLength()
Get the content length.

Returns:
Number of bytes until EOF is returned or -1 for no limit.

getTrailer

public HttpFields getTrailer()

destroy

public void destroy()


Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.