All Packages Class Hierarchy This Package Previous Next Index
Class sun.servlet.http.HttpInputStream
java.lang.Object
|
+----java.io.InputStream
|
+----javax.servlet.ServletInputStream
|
+----sun.servlet.http.HttpInputStream
- public class HttpInputStream
- extends ServletInputStream
This class implements a buffered input stream for reading servlet request
data. It also keeps track of the number of bytes that have been read, and
allows the specification of an optional byte limit to ensure that the
content length has not been exceeded.
-
buf
- The input buffer.
-
count
- The current number of bytes in the buffer.
-
in
- The actual input stream for this request.
-
length
- The content length for this request.
-
limit
- The maximum number of bytes for the current request.
-
pos
- The current position in the buffer.
-
total
- The total number of bytes for the current request.
-
HttpInputStream()
- Creates a new, uninitialized input stream using a default
buffer size.
-
HttpInputStream(int)
- Creates a new, uninitialized input stream using the specified
buffer size.
-
available()
- Returns the number of bytes that can be read without blocking.
-
close()
- Closes the input stream.
-
fill()
- Fills input buffer with more bytes.
-
finish()
- Finishes reading the request without closing the underlying stream.
-
getContentLength()
- Returns the content length for this input stream, or -1 if not set.
-
getTotal()
- Returns the total number of bytes read so far.
-
init(InputStream)
- Initializes the servlet input stream with the specified raw input stream.
-
next()
- Begins reading the next request.
-
read()
- Reads a byte of data.
-
read(byte[], int, int)
- Reads into an array of bytes.
-
readLine(byte[], int, int)
- Reads into an array of bytes until all requested bytes have been
read or a '\n' is encountered, in which case the '\n' is read into
the array as well.
-
resets()
- Resets the input stream for a new connection.
-
setContentLength(int)
- Sets the content length for this input stream.
-
skip(long)
- Skips n bytes of input.
in
protected InputStream in
- The actual input stream for this request.
buf
protected byte buf[]
- The input buffer.
count
protected int count
- The current number of bytes in the buffer.
pos
protected int pos
- The current position in the buffer.
total
protected int total
- The total number of bytes for the current request.
limit
protected int limit
- The maximum number of bytes for the current request.
length
protected int length
- The content length for this request.
HttpInputStream
public HttpInputStream(int size)
- Creates a new, uninitialized input stream using the specified
buffer size.
- Parameters:
- size - the input buffer size
HttpInputStream
public HttpInputStream()
- Creates a new, uninitialized input stream using a default
buffer size.
init
public void init(InputStream in) throws IOException
- Initializes the servlet input stream with the specified raw input stream.
- Parameters:
- in - the raw input stream
next
public void next()
- Begins reading the next request.
finish
public void finish() throws IOException
- Finishes reading the request without closing the underlying stream.
- Throws: IOException
- if an I/O error has occurred
resets
public void resets()
- Resets the input stream for a new connection.
getTotal
public int getTotal()
- Returns the total number of bytes read so far.
setContentLength
public void setContentLength(int len)
- Sets the content length for this input stream. This should be called
once the headers have been read from the input stream.
- Parameters:
- len - the content length
getContentLength
public int getContentLength()
- Returns the content length for this input stream, or -1 if not set.
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 or
the content length has been exceeded
- Throws: IOException
- if an I/O error has occurred
- Overrides:
- read in class InputStream
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 read
- Returns:
- the actual number of bytes read, or -1 if the end of the
stream is reached or the byte limit has been exceeded
- Throws: IOException
- if an I/O error has occurred
- Overrides:
- read in class InputStream
readLine
public int readLine(byte b[],
int off,
int len) throws IOException
- Reads into an array of bytes until all requested bytes have been
read or a '\n' is encountered, in which case the '\n' is read into
the array as well.
- 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
stream is reached or the byte limit has been exceeded
- Throws: IOException
- if an I/O error has occurred
- Overrides:
- readLine in class ServletInputStream
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
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
close
public void close() throws IOException
- Closes the input stream.
- Throws: IOException
- if an I/O error has occurred
- Overrides:
- close in class InputStream
fill
protected void fill() throws IOException
- Fills input buffer with more bytes.
All Packages Class Hierarchy This Package Previous Next Index