public class StringBufferInputStream
extends InputStream
| java.lang.Object | ||
| ↳ | java.io.InputStream | |
| ↳ | java.io.StringBufferInputStream | |
此类已在API级别1中弃用。
该类不能正确地将字符转换为字节。 从JDK 1.1开始,从字符串创建流的首选方法是通过StringReader类。
该类允许应用程序创建一个输入流,其中读取的字节由字符串的内容提供。 应用程序还可以使用ByteArrayInputStream从字节数组中读取字节。
该类只使用字符串中每个字符的低八位。
也可以看看:
Fields |
|
|---|---|
protected String |
buffer 从中读取字节的字符串。 |
protected int |
count 输入流缓冲区中的有效字符数。 |
protected int |
pos 从输入流缓冲区读取的下一个字符的索引。 |
Public constructors |
|
|---|---|
StringBufferInputStream(String s) 创建一个字符串输入流以从指定的字符串中读取数据。 |
|
Public methods |
|
|---|---|
int |
available() 返回可以不受阻塞地从输入流中读取的字节数。 |
int |
read() 从此输入流中读取下一个字节的数据。 |
int |
read(byte[] b, int off, int len) 从该输入流中最多读取 |
void |
reset() 重置输入流以开始从此输入流的基础缓冲区的第一个字符开始读取。 |
long |
skip(long n) 从此输入流跳过 |
Inherited methods |
|
|---|---|
java.io.InputStream
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
StringBufferInputStream (String s)
创建一个字符串输入流以从指定的字符串中读取数据。
| Parameters | |
|---|---|
s |
String: the underlying input buffer. |
int available ()
返回可以不受阻塞地从输入流中读取的字节数。
| Returns | |
|---|---|
int |
the value of count - pos, which is the number of bytes remaining to be read from the input buffer. |
int read ()
从此输入流中读取下一个字节的数据。 值字节被返回作为int范围0到255 。 如果由于已到达流的末尾而没有字节可用,则返回值-1 。
read方法StringBufferInputStream不能阻塞。 它返回此输入流缓冲区中下一个字符的低八位。
| Returns | |
|---|---|
int |
the next byte of data, or -1 if the end of the stream is reached. |
int read (byte[] b,
int off,
int len)
将最多 len个字节的数据从此输入流读入到一个字节数组中。
该read的方法StringBufferInputStream不能阻止。 它将该输入流缓冲区中字符的低8位复制到字节数组参数中。
| Parameters | |
|---|---|
b |
byte: the buffer into which the data is read. |
off |
int: the start offset of the data. |
len |
int: the maximum number of bytes read. |
| Returns | |
|---|---|
int |
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached. |
long skip (long n)
从此输入流跳过n个字节的输入。 如果到达输入流的末尾,则可以跳过更少的字节。
| Parameters | |
|---|---|
n |
long: the number of bytes to be skipped. |
| Returns | |
|---|---|
long |
the actual number of bytes skipped. |