InputStream的作用是标志那些从不同数据起源产生输入的类。这些数据起源包括(每个都有一个相关的InputStream子类):
(2) String对象
(3) 文件
(4) “管道”,它的工作原理与现实生活中的管道类似:将一些东西一端置入,它们在另一端输出。
(5) 一个由其他种类的流组成的序列,以便我们将其统一收集合并到一个流内。
(6) 其他数据集,如Internet连接等。
除此以外,FilterInputStream也属于InputStream的一种类型,用它可为“破坏器”类提供一个基础类,以便将属性或者有用的接口同输入流连接到一起。这将在以后讨论。
| Class | Function | Constructor Arguments | How to use it |
|---|---|---|---|
|
ByteArray-InputStream
|
Allows a buffer in memory to be used as an
InputStream.
|
The buffer from which to extract the bytes.
|
As a source of data. Connect it to a FilterInputStreamobject to provide a useful interface. |
|
StringBuffer-InputStream
|
Converts a
Stringinto an
InputStream.
|
A
String. The underlying implementation actually uses a
StringBuffer.
|
As a source of data. Connect it to a FilterInputStreamobject to provide a useful interface. |
|
File-InputStream
|
For reading information from a file.
|
A
Stringrepresenting the file name, or a
Fileor
FileDescriptorobject.
|
As a source of data. Connect it to a FilterInputStreamobject to provide a useful interface. |
类 功能 构建器参数/如何使用
ByteArrayInputStream 允许内存中的一个缓冲区作为InputStream使用 从中提取字节的缓冲区/作为一个数据源使用。通过将其同一个FilterInputStream对象连接,可提供一个有用的接口
StringBufferInputStream 将一个String转换成InputStream 一个String(字串)。基础的实施方案实际采用一个StringBuffer(字串缓冲)/作为一个数据源使用。通过将其同一个FilterInputStream对象连接,可提供一个有用的接口
FileInputStream 用于从文件读取信息 代表文件名的一个String,或者一个File或FileDescriptor对象/作为一个数据源使用。通过将其同一个FilterInputStream对象连接,可提供一个有用的接口
|
Piped-InputStream
|
Produces the data that’s being written to the associated
PipedOutput-Stream. Implements the “piping” concept.
|
PipedOutputStream | As a source of data in multithreading. Connect it to a FilterInputStreamobject to provide a useful interface. |
|
Sequence-InputStream
|
Coverts two or more
InputStreamobjects into a single
InputStream.
|
Two
InputStreamobjects or an
Enumerationfor a container of
InputStreamobjects.
|
As a source of data. Connect it to a FilterInputStreamobject to provide a useful interface. |
|
Filter-InputStream
|
Abstract class which is an interface for decorators that provide useful functionality to the other
InputStreamclasses. See Table 10-3.
|
See Table 10-3.
|
See Table 10-3. |
PipedInputString 产生为相关的PipedOutputStream写的数据。实现了“管道化”的概念 PipedOutputStream/作为一个数据源使用。通过将其同一个FilterInputStream对象连接,可提供一个有用的接口
SequenceInputStream 将两个或更多的InputStream对象转换成单个InputStream使用 两个InputStream对象或者一个Enumeration,用于InputStream对象的一个容器/作为一个数据源使用。通过将其同一个FilterInputStream对象连接,可提供一个有用的接口
FilterInputStream对作为破坏器接口使用的类进行抽象;那个破坏器为其他InputStream类提供了有用的功能。参见表10.3
