public class ByteArrayInputStream extends InputStream
ByteArrayInputStream包含一个内部缓冲区包含的字节,可以从流中读取。一个内部计数器跟踪下一个字节是由
read提供的方法。
关闭ByteArrayInputStream没有影响。这个类中的方法可以在流一直没有产生一个IOException闭叫。
StringBufferInputStream
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
由流的创建者提供的字节数组。
|
protected int |
count
输入流缓冲区中的最后一个有效字符的索引一个大于。
|
protected int |
mark
当前在流中的标记位置。
|
protected int |
pos
从输入流缓冲区读取的下一个字符的索引。
|
| Constructor and Description |
|---|
ByteArrayInputStream(byte[] buf)
创建一个
ByteArrayInputStream以便它使用
buf作为缓冲数组。
|
ByteArrayInputStream(byte[] buf, int offset, int length)
创建
ByteArrayInputStream使用
buf作为缓冲数组。
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
返回从该输入流读取的剩余字节数(或跳过)。
|
void |
close()
关闭
ByteArrayInputStream没有影响。
|
void |
mark(int readAheadLimit)
在流中设置当前标记位置。
|
boolean |
markSupported()
如果这个测试
InputStream支持马克/复位。
|
int |
read()
从这个输入流读取下一个数据字节。
|
int |
read(byte[] b, int off, int len)
读到
len数据从输入流中的字节数组的字节。
|
void |
reset()
重置缓存到标记的位置。
|
long |
skip(long n)
跳过
n字节的输入从输入流。
|
readprotected byte[] buf
buf[0]
buf[count-1]是唯一能从流中读取字节;元
buf[pos]是下一个要读取的字节。
protected int pos
count价值。是从输入流的缓冲中读取下一个字节将
buf[pos]。
protected int mark
mark()方法。缓冲区的当前位置设置为该点的
reset()方法。
如果没有设置标记,则标记的值是传递给构造函数的偏移量(如果不提供偏移量,则为0)。
protected int count
buf长度。这是一个比一个大的最后一个字节,在
buf能从输入流的缓冲中读取位置。
public ByteArrayInputStream(byte[] buf)
ByteArrayInputStream以便它使用
buf作为缓冲数组。未复制缓冲区数组。
pos的初始值是
0和
count初始值是
buf长度。
buf -输入缓冲区。
public ByteArrayInputStream(byte[] buf,
int offset,
int length)
ByteArrayInputStream使用
buf作为缓冲数组。
pos的初始值是
offset和
count初始值是
offset+length和
buf.length最小。未复制缓冲区数组。缓冲区的标记被设置为指定的偏移量。
buf -输入缓冲区。
offset -在第一个字节的缓冲区偏移读。
length -从缓冲区读取的最大字节数。
public int read()
0一
int到
255返回。如果没有可用的字节,因为已到达流的末尾,则返回值
-1。
这read方法不能阻止。
read 方法重写,继承类
InputStream
-1如果已到达流的末尾。
public int read(byte[] b,
int off,
int len)
len字节的数据从输入流中的字节数组。如果
pos等于
count,然后
-1返回表示文件结束。否则,
k读取的字节数等于
len和
count-pos较小。如果
k是积极的,那么
buf[pos]通过
buf[pos+k-1]字节复制到
b[off]通过的方式进行
System.arraycopy
b[off+k-1]。价值
k加入
pos和
k返回。
这read方法不能阻止。
read 方法重写,继承类
InputStream
b -缓冲区中读取数据。
off -目标数组
b的起始偏移量
len -的最大字节数读。
-1如果没有更多的数据,因为已到达流的末尾。
null
b
NullPointerException。
IndexOutOfBoundsException -如果
off是负的,
len是负的,或
len大于
b.length - off
InputStream.read()
public long skip(long n)
n字节的输入从输入流。如果达到输入流的结尾,则可能会跳过更少的字节数。要跳过的字节的实际数量
k等于
n和
count-pos较小。价值
k加入
pos和
k返回。
skip 方法重写,继承类
InputStream
n -字节数被跳过。
public int available()
返回值count - pos,这是有待从输入缓冲区读取的字节数。
available 方法重写,继承类
InputStream
public boolean markSupported()
InputStream支持马克/复位。对
ByteArrayInputStream的
markSupported方法总是返回
true。
markSupported 方法重写,继承类
InputStream
true流实例支持的标记和复位方法;
false否则。
InputStream.mark(int),
InputStream.reset()
public void mark(int readAheadLimit)
如果没有设置标记,则标记的值是传递给构造函数的偏移量(如果不提供偏移量,则为0)。
注意:这个类的readAheadLimit没有意义。
mark 方法重写,继承类
InputStream
readAheadLimit -字节可以在标记位置无效阅读最大限度。
InputStream.reset()
public void reset()
reset 方法重写,继承类
InputStream
InputStream.mark(int),
IOException
public void close()
throws IOException
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.