Class ServletInputStream
java.lang.Object
java.io.InputStream
javax.servlet.ServletInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
This class serves as a stream where servlets can read data supplied by
the client from.
- Since:
- Servlet API 1.0
- Version:
- Servlet API 2.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintreadLine(byte[] buffer, int offset, int length) This method read bytes from a stream and stores them into a caller supplied buffer.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
ServletInputStream
protected ServletInputStream()Does nothing.- Since:
- Servlet API 1.0
-
-
Method Details
-
readLine
This method read bytes from a stream and stores them into a caller supplied buffer. It starts storing the data at indexoffsetinto the buffer and attempts to read until a end of line ('\n') is encountered orlengthbytes are read. This method can return before reading the number of bytes requested. The actual number of bytes read is returned as an int. A -1 is returned to indicate the end of the stream. This method will block until some data can be read. This method operates by calling the single byteread()method in a loop until the desired number of bytes are read. The read loop stops short if the end of the stream is encountered or if an IOException is encountered on any read operation except the first. If the first attempt to read a bytes fails, the IOException is allowed to propagate upward. And subsequent IOException is caught and treated identically to an end of stream condition. Subclasses can (and should if possible) override this method to provide a more efficient implementation.- Parameters:
buffer- The array into which the bytes read should be storedoffset- The offset into the array to start storing byteslength- The maximum number of bytes to read- Returns:
- The actual number of bytes read, or -1 if end of stream.
- Throws:
IOException- If an error occurs.- Since:
- Servlet API 1.0
-