Most visited

Recently visited

Added in API level 1

CharArrayReader

public class CharArrayReader
extends Reader

java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.CharArrayReader


这个类实现了一个可以用作字符输入流的字符缓冲区。

Summary

Fields

protected char[] buf

字符缓冲区。

protected int count

此缓冲区结束的索引。

protected int markedPos

标记在缓冲区中的位置。

protected int pos

当前的缓冲区位置。

Inherited fields

From class java.io.Reader

Public constructors

CharArrayReader(char[] buf)

从指定的字符数组创建一个CharArrayReader。

CharArrayReader(char[] buf, int offset, int length)

从指定的字符数组创建一个CharArrayReader。

Public methods

void close()

关闭流并释放与其关联的所有系统资源。

void mark(int readAheadLimit)

标记流中的当前位置。

boolean markSupported()

告诉这个流是否支持mark()操作。

int read()

读取一个字符。

int read(char[] b, int off, int len)

将字符读入数组的一部分。

boolean ready()

告诉这个流是否准备好被读取。

void reset()

将流重置为最近的标记,或者在从未标记的情况下将流重置为开始。

long skip(long n)

跳过字符。

Inherited methods

From class java.io.Reader
From class java.lang.Object
From interface java.lang.Readable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Fields

buf

Added in API level 1
char[] buf

字符缓冲区。

count

Added in API level 1
int count

此缓冲区结束的索引。 没有有效的数据在这个索引或超出这个索引。

markedPos

Added in API level 1
int markedPos

标记在缓冲区中的位置。

pos

Added in API level 1
int pos

当前的缓冲区位置。

Public constructors

CharArrayReader

Added in API level 1
CharArrayReader (char[] buf)

从指定的字符数组创建一个CharArrayReader。

Parameters
buf char: Input buffer (not copied)

CharArrayReader

Added in API level 1
CharArrayReader (char[] buf, 
                int offset, 
                int length)

从指定的字符数组创建一个CharArrayReader。

由此产生的读者将开始阅读给定的offset 可以从此读取器读取的总数char值为lengthbuf.length-offset ,以较小者为准。

Parameters
buf char: Input buffer (not copied)
offset int: Offset of the first char to read
length int: Number of chars to read
Throws
IllegalArgumentException If offset is negative or greater than buf.length, or if length is negative, or if the sum of these two values is negative.

Public methods

close

Added in API level 1
void close ()

关闭流并释放与其关联的所有系统资源。 一旦流被关闭,read(),ready(),mark(),reset()或skip()调用将会抛出一个IOException异常。 关闭以前关闭的流不起作用。

mark

Added in API level 1
void mark (int readAheadLimit)

标记流中的当前位置。 随后调用reset()会将流重新定位到这一点。

Parameters
readAheadLimit int: Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from a character array, there is no actual limit; hence this argument is ignored.
Throws
IOException If an I/O error occurs

markSupported

Added in API level 1
boolean markSupported ()

告诉这个流是否支持mark()操作。

Returns
boolean true if and only if this stream supports the mark operation.

read

Added in API level 1
int read ()

读取一个字符。

Returns
int The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws
IOException If an I/O error occurs

read

Added in API level 1
int read (char[] b, 
                int off, 
                int len)

将字符读入数组的一部分。

Parameters
b char: Destination buffer
off int: Offset at which to start storing characters
len int: Maximum number of characters to read
Returns
int The actual number of characters read, or -1 if the end of the stream has been reached
Throws
IOException If an I/O error occurs

ready

Added in API level 1
boolean ready ()

告诉这个流是否准备好被读取。 字符阵列阅读器随时可以阅读。

Returns
boolean True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws
IOException If an I/O error occurs

reset

Added in API level 1
void reset ()

将流重置为最近的标记,或者在从未标记的情况下将流重置为开始。

Throws
IOException If an I/O error occurs

skip

Added in API level 1
long skip (long n)

跳过字符。 返回跳过的字符数。

即使Reader超类的skip方法在此情况下引发异常, n参数也可能为负数。 如果n为负数,则此方法不做任何处理并返回0

Parameters
n long: The number of characters to skip
Returns
long The number of characters actually skipped
Throws
IOException If the stream is closed, or an I/O error occurs

Hooray!