public class SequenceInputStream extends InputStream
SequenceInputStream表示其他输入流的逻辑级联。
它从一个有序的输入流集合开始,从第一个读取到文件的结尾,然后从第二个文件读取,依此类推,直到最后一个输入流达到文件的结尾。
| Constructor and Description |
|---|
SequenceInputStream(Enumeration<? extends InputStream> e)
初始化新创建
SequenceInputStream通过记住参数,它必须是一个
Enumeration产生对象,它们的运行时类型是
InputStream 。
|
SequenceInputStream(InputStream s1, InputStream s2)
通过记住两个
SequenceInputStream来初始化新创建的SequenceInputStream,这些参数将按顺序读取,首先是
s1 ,然后是
s2 ,以提供要从此
SequenceInputStream读取的字节。
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
返回当前底层输入流可以读取(或跳过)的字节数,而不会被下一次调用当前底层输入流的方法阻塞。
|
void |
close()
关闭此输入流并释放与流相关联的任何系统资源。
|
int |
read()
从该输入流读取下一个数据字节。
|
int |
read(byte[] b, int off, int len)
从该输入流读取最多
len个字节的数据到字节数组。
|
mark, markSupported, read, reset, skippublic SequenceInputStream(Enumeration<? extends InputStream> e)
SequenceInputStream ,该参数必须是Enumeration ,它生成运行时类型为InputStream 。
由枚举产生的输入流将按顺序读取,以提供要从此SequenceInputStream读取的字节。
从枚举的每个输入流都用完后,通过调用其close方法关闭它。
e - 输入流的枚举。
Enumeration
public SequenceInputStream(InputStream s1, InputStream s2)
SequenceInputStream来初始化新创建的
SequenceInputStream ,这两个参数将按顺序读取,首先是
s1 ,然后是
s2 ,以提供要从该
SequenceInputStream读取的字节。
s1 - 要读取的第一个输入流。
s2 - 要读取的第二个输入流。
public int available()
throws IOException
此方法仅调用available当前底层输入流的并返回结果。
available在
InputStream
0该输入流是否已调用它的关闭
close()方法
IOException - 如果发生I / O错误。
public int read()
throws IOException
int返回,范围为0至255 。
如果没有字节可用,因为流已经到达,则返回值-1 。
该方法阻塞直到输入数据可用,检测到流的结尾,或抛出异常。
此方法尝试从当前子流中读取一个字符。 如果它到达流的末尾,它调用当前子流的close方法,并从下一个子流开始读取。
read在
InputStream
-1 。
IOException - 如果发生I / O错误。
public int read(byte[] b,
int off,
int len)
throws IOException
len字节的数据到字节数组。
如果len不为零,该方法将阻塞,直到输入的至少1个字节可用;
否则,不会读取字节,并返回0 。
该read的方法SequenceInputStream试图从当前子流读取数据。 如果由于子流已达到流的末尾而无法读取任何字符,则会调用当前子流的close方法,并从下一个子流开始读取。
read在类别
InputStream
b - 读取数据的缓冲区。
off - 写入数据的数组
b中的起始偏移量。
len - 读取的最大字节数。
NullPointerException - 如果
b是
null 。
IndexOutOfBoundsException - 如果
off为负,则
len为负数,或
len大于
b.length - off
IOException - 如果发生I / O错误。
InputStream.read()
public void close()
throws IOException
SequenceInputStream无法执行输入操作,无法重新打开。
如果此流是从枚举创建的,则所有剩余元素都将从枚举中请求,并在close方法返回之前关闭。
close在界面
Closeable
close在界面
AutoCloseable
close在类别
InputStream
IOException - 如果发生I / O错误。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.