|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.ByteArrayInputStream
public class ByteArrayInputStream
ByteArrayInputStream 包含一个内部缓冲区,该缓冲区包含从流中读取的字节。内部计数器跟踪 read 方法要提供的下一个字节。
关闭 ByteArrayInputStream 无效。此类中的方法在关闭此流后仍可被调用,而不会产生任何 IOException。
StringBufferInputStream| 字段摘要 | |
|---|---|
protected byte[] |
buf
由该流的创建者提供的 byte 数组。 |
protected int |
count
比输入流缓冲区中最后一个有效字符的索引大一的索引。 |
protected int |
mark
流中当前的标记位置。 |
protected int |
pos
要从输入流缓冲区中读取的下一个字符的索引。 |
| 构造方法摘要 | |
|---|---|
ByteArrayInputStream(byte[] buf)
创建一个 ByteArrayInputStream,使用 buf 作为其缓冲区数组。 |
|
ByteArrayInputStream(byte[] buf,
int offset,
int length)
创建 ByteArrayInputStream,使用 buf 作为其缓冲区数组。 |
|
| 方法摘要 | |
|---|---|
int |
available()
返回可从此输入流读取(或跳过)的剩余字节数。 |
void |
close()
关闭 ByteArrayInputStream 无效。 |
void |
mark(int readAheadLimit)
设置流中的当前标记位置。 |
boolean |
markSupported()
测试此 InputStream 是否支持 mark/reset。 |
int |
read()
从此输入流中读取下一个数据字节。 |
int |
read(byte[] b,
int off,
int len)
将最多 len 个数据字节从此输入流读入 byte 数组。 |
void |
reset()
将缓冲区的位置重置为标记位置。 |
long |
skip(long n)
从此输入流中跳过 n 个输入字节。 |
| 从类 java.io.InputStream 继承的方法 |
|---|
read |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
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 到 255 范围内的 int 字节值。如果因为到达流末尾而没有可用的字节,则返回值 -1。
此 read 方法不会阻塞。
InputStream 中的 read-1。
public int read(byte[] b,
int off,
int len)
len 个数据字节从此输入流读入 byte 数组。如果 pos 等于 count,则返回 -1 指示文件结束。否则,读取的字节数 k 等于 len 和 count-pos 中的较小者。如果 k 是正数,则以 System.arraycopy 执行的方式将 buf[pos] 到 buf[pos+k-1] 的字节复制到 b[off] 到 b[off+k-1] 中。将值 k 与 pos 相加并返回 k。
此 read 方法不会阻塞。
InputStream 中的 readb - 存储读入数据的缓冲区。off - 目标数组 b 的起始偏移量。len - 读取的最大字节数。
-1。
NullPointerException - 如果 b 为 null。
IndexOutOfBoundsException - 如果 off 为负,len 为负,或者 len 大于 b.length - offInputStream.read()public long skip(long n)
n 个输入字节。如果已到达输入流末尾,则可能会跳过较少的字节。实际跳过的字节数 k 等于 n 和 count-pos 中的较小者。将值 k 与 pos 相加并返回 k。
InputStream 中的 skipn - 要跳过的字节数。
public int available()
返回值是 count - pos,它是要从输入缓冲区中读取的剩余字节数。
InputStream 中的 availablepublic boolean markSupported()
InputStream 是否支持 mark/reset。ByteArrayInputStream 的 markSupported 方法始终返回 true。
InputStream 中的 markSupportedtrue;否则返回 false。InputStream.mark(int),
InputStream.reset()public void mark(int readAheadLimit)
如果尚未设置标记,则标记值是传递给构造方法的偏移量(如果未提供偏移量,则标记值为 0)。
注:readAheadLimit 对于此类没有意义。
InputStream 中的 markreadAheadLimit - 在标记位置失效前可以读取字节的最大限制。InputStream.reset()public void reset()
InputStream 中的 resetInputStream.mark(int),
IOException
public void close()
throws IOException
Closeable 中的 closeInputStream 中的 closeIOException - 如果发生 I/O 错误。
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。