ServletInputStream (Java EE 5)

Java EE API


javax.servlet Class ServletInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by javax.servlet.ServletInputStream
All Implemented Interfaces:
Closeable

public abstract class ServletInputStream
extends InputStream

Extends: java.io.InputStream

提供用于读取客户端请求中的二进制数据的输入流,包括一个高效的 readLine 方法用于一次读取一行数据。使用一些协议(比如 HTTP POST 和 PUT),ServletInputStream 对象可用于读取从客户端发送的数据。

ServletInputStream 对象通常是通过 ServletRequest#getInputStream 方法获取的。

这是 servlet 容器实现的一个抽象类。此类的子类必须实现 java.io.InputStream.read() 方法。

英文文档:

Provides an input stream for reading binary data from a client request, including an efficient readLine method for reading data one line at a time. With some protocols, such as HTTP POST and PUT, a ServletInputStream object can be used to read data sent from the client.

A ServletInputStream object is normally retrieved via the ServletRequest.getInputStream() method.

This is an abstract class that a servlet container implements. Subclasses of this class must implement the java.io.InputStream.read() method.

Author:
Various
See Also:
ServletRequest

Constructor Summary
protected
 
Method Summary
 int
 
Methods inherited from class java.io.InputStream
 
Methods inherited from class java.lang.Object
 

Constructor Detail

protected ServletInputStream()
不执行任何操作,因为这是一个抽象类。
英文文档:

ServletInputStream

protected ServletInputStream()
Does nothing, because this is an abstract class.

Method Detail

public int readLine(byte[] b, int off, int len) throws java.io.IOException
以一次一行的形式读取输入流。从某个偏移量开始将字节读入数组,直到读取特定数量的字节,或者到达换行符为止,该字符也将读入数组。

如果在读取到最大字节数之前到达输入流末尾,则此方法返回 -1。

b 将数据读入其中的 byte 数组
off 指定此方法开始读取的字符的整数
len 指定要读取的最大字节数的整数
return 指定读取的实际字节数的整数,如果到达流末尾,则返回 -1
Throwsjava.io.IOException: 如果发生输入或输出异常

英文文档:

readLine

public int readLine(byte[] b,
                    int off,
                    int len)
             throws IOException
Reads the input stream, one line at a time. Starting at an offset, reads bytes into an array, until it reads a certain number of bytes or reaches a newline character, which it reads into the array as well.

This method returns -1 if it reaches the end of the input stream before reading the maximum number of bytes.

Parameters:
b - an array of bytes into which data is read
off - an integer specifying the character at which this method begins reading
len - an integer specifying the maximum number of bytes to read
Returns:
an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached
Throws:
IOException - if an input or output exception has occurred


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!