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 字节的输入从输入流。
|
read
protected 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.