public class SequenceInputStream
extends InputStream
| java.lang.Object | ||
| java.io.InputStream | ||
| java.io.SequenceInputStream | ||
一个SequenceInputStream表示其他输入流的逻辑连接。 它从输入流的有序集合开始,并从第一个读取到文件结束,然后从第二个读取,依此类推,直到最后一个包含的输入流达到文件结束。
Public constructors |
|
|---|---|
SequenceInputStream(Enumeration<? extends InputStream> e) 初始化新创建 |
|
SequenceInputStream(InputStream s1, InputStream s2) 通过记住两个参数来初始化新创建的 |
|
公共方法(Public methods) |
|
|---|---|
int |
available() 返回可从当前底层输入流读取(或跳过)的字节数的估计值,而不会因当前底层输入流的方法的下一次调用而被阻止。 |
void |
close() 关闭此输入流并释放与该流关联的所有系统资源。 |
int |
read() 从此输入流中读取下一个字节的数据。 |
int |
read(byte[] b, int off, int len) 最多可将 |
继承方法(Inherited methods) |
|
|---|---|
java.io.InputStream
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
SequenceInputStream (Enumeration<? extends InputStream> e)
初始化新创建SequenceInputStream通过记住参数,它必须是一个Enumeration产生对象,它们的运行时类型是InputStream 。 由枚举产生的输入流将被读取,以便提供从这个SequenceInputStream读取的字节。 在枚举中的每个输入流用完后,通过调用其close方法关闭它。
| 参数(Parameters) | |
|---|---|
e |
Enumeration: an enumeration of input streams. |
也可以看看:
SequenceInputStream (InputStream s1, InputStream s2)
通过记住两个参数来初始化新创建的 SequenceInputStream ,这些参数将按顺序读取,首先是 s1 ,然后是 s2 ,以提供要从此 SequenceInputStream读取的字节。
| 参数(Parameters) | |
|---|---|
s1 |
InputStream: the first input stream to read. |
s2 |
InputStream: the second input stream to read. |
int available ()
返回可从当前底层输入流读取(或跳过)的字节数的估计值,而不会因当前底层输入流的方法的下一次调用而被阻止。 下一次调用可能是同一个线程或另一个线程。 单个读取或跳过这么多字节不会被阻塞,但可以读取或跳过更少的字节。
此方法只需调用当前基础输入流的 available并返回结果。
| 返回(Returns) | |
|---|---|
int |
an estimate of the number of bytes that can be read (or skipped over) from the current underlying input stream without blocking or 0 if this input stream has been closed by invoking its close() method |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
void close ()
关闭此输入流并释放与该流关联的所有系统资源。 关闭的SequenceInputStream无法执行输入操作,无法重新打开。
如果此流由枚举创建,则所有其余元素都将从枚举中请求并在 close方法返回之前关闭。
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
int read ()
从此输入流中读取下一个字节的数据。 该字节以int的范围0到255 。 如果由于流的末尾已到达而没有可用字节,则返回值-1 。 此方法阻塞直到输入数据可用,流的末尾被检测到,或抛出异常。
此方法尝试从当前子流读取一个字符。 如果它到达流的末尾,它将调用当前子流的close方法,并开始从下一个子流读取数据。
| 返回(Returns) | |
|---|---|
int |
the next byte of data, or -1 if the end of the stream is reached. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
int read (byte[] b,
int off,
int len)
从该输入流读取多达len个字节的数据到一个字节数组中。 如果len不为零,则方法会阻塞,直到输入的至少1个字节可用; 否则,不读取字节并返回0 。
该read的方法SequenceInputStream试图从当前子流读取数据。 如果由于子流已到达流末尾而无法读取任何字符,它将调用当前子流的close方法,并开始从下一个子流读取数据。
| 参数(Parameters) | |
|---|---|
b |
byte: the buffer into which the data is read. |
off |
int: the start offset in array b at which the data is written. |
len |
int: the maximum number of bytes read. |
| 返回(Returns) | |
|---|---|
int |
int the number of bytes read. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
If b is null. |
IndexOutOfBoundsException |
If off is negative, len is negative, or len is greater than b.length - off |
IOException |
if an I/O error occurs. |