Class sun.server.http.HttpInputStream
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.server.http.HttpInputStream

java.lang.Object
   |
   +----java.io.InputStream
           |
           +----java.servlet.ServletInputStream
                   |
                   +----sun.server.http.HttpInputStream

public class HttpInputStream
extends ServletInputStream
implements AlarmHandler
A buffered input stream for reading HTTP server requests. Unlike java.io.BufferedInputStream, this class is not synchronized in order to be as efficient as possible. Consequently, it is not MT-safe so must be used carefully in servlets that create multiple threads. This class also includes additional support for automatically closing the connection when input becomes idle, in order to support keep-alive.

Variable Index

 o alarm
The alarm for supporting timeout on input.
 o am
 o buf
The buffer where input data is stored.
 o chunkIn
If we are doing chunking, delegate to this stream.
 o chunking
Whether we are doing HTTP/1.1 chunking or not.
 o closed
Set to true when the connection is closed.
 o count
The number of bytes in the buffer.
 o in
The socket input stream.
 o pos
The current position in the buffer.
 o timeout
The maximum time to block while reading before the input stream is closed.

Constructor Index

 o HttpInputStream()
Creates a new HTTP input stream with a default buffer size.
 o HttpInputStream(int)
Creates a new HTTP input stream with the specified buffer size.

Method Index

 o available()
Returns the number of bytes that can be read without blocking.
 o close()
Closes the input stream.
 o eof()
Returns true if at end of stream.
 o fill()
Fills the input buffer with more data.
 o handleAlarm(Alarm)
The handler for timeout alarm events.
 o read()
Reads a byte of data.
 o read(byte[], int, int)
Reads into an array of bytes.
 o readLine(byte[], int, int)
Reads bytes into the specified byte array until the array is filled or a newline character is read.
 o reset(InputStream, long)
Resets the input stream for a new connection.
 o skip(long)
Skips n bytes of input.
 o startChunking()
Use HTTP/1.1 chunking for input.

Variables

 o am
  protected static AlarmManager am
 o in
  protected InputStream in
The socket input stream.
 o buf
  protected byte buf[]
The buffer where input data is stored.
 o count
  protected int count
The number of bytes in the buffer.
 o pos
  protected int pos
The current position in the buffer.
 o alarm
  protected Alarm alarm
The alarm for supporting timeout on input.
 o timeout
  protected long timeout
The maximum time to block while reading before the input stream is closed.
 o closed
  protected boolean closed
Set to true when the connection is closed.
 o chunking
  protected boolean chunking
Whether we are doing HTTP/1.1 chunking or not.
 o chunkIn
  protected ChunkedInputStream chunkIn
If we are doing chunking, delegate to this stream.

Constructors

 o HttpInputStream
  public HttpInputStream(int size)
Creates a new HTTP input stream with the specified buffer size.
Parameters:
size - the input buffer size
 o HttpInputStream
  public HttpInputStream()
Creates a new HTTP input stream with a default buffer size.

Methods

 o reset
  public void reset(InputStream in,
                    long timeout)
Resets the input stream for a new connection.
Parameters:
in - the socket input stream
timeout - input idle timeout
 o read
  public int read() throws IOException
Reads a byte of data. This method will block if no input is available.
Returns:
the byte read, or -1 if the end of the stream is reached.
Throws: IOException
If an I/O error has occurred.
Overrides:
read in class InputStream
 o read
  public int read(byte b[],
                  int off,
                  int len) throws IOException
Reads into an array of bytes. This method will block until some input is available.
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes to read
Returns:
the actual number of bytes read, or -1 if the end of the stream is reached.
Throws: IOException
If an I/O error has occurred.
Overrides:
read in class InputStream
 o readLine
  public int readLine(byte b[],
                      int off,
                      int len) throws IOException
Reads bytes into the specified byte array until the array is filled or a newline character is read.
Parameters:
b - the buffer where data is stored
off - the start offset of the data
len - the length of the data
Returns:
the actual number of bytes read, or -1 if the end of the file has been reached.
Throws: IOException
If an I/O error has occurred.
Overrides:
readLine in class ServletInputStream
 o skip
  public long skip(long n) throws IOException
Skips n bytes of input.
Parameters:
n - the number of bytes to skip
Returns:
the actual number of bytes skipped.
Throws: IOException
If an I/O error has occurred.
Overrides:
skip in class InputStream
 o available
  public int available() throws IOException
Returns the number of bytes that can be read without blocking.
Returns:
the number of available bytes.
Throws: IOException
If an I/O error has occurred.
Overrides:
available in class InputStream
 o eof
  public boolean eof() throws IOException
Returns true if at end of stream.
Throws: IOException
If an I/O error has occurred.
 o fill
  protected void fill() throws IOException
Fills the input buffer with more data.
 o handleAlarm
  public void handleAlarm(Alarm alarm)
The handler for timeout alarm events.
 o close
  public void close()
Closes the input stream.
Overrides:
close in class InputStream
 o startChunking
  public void startChunking()
Use HTTP/1.1 chunking for input.

All Packages  Class Hierarchy  This Package  Previous  Next  Index