CharArrayReader Introduction
CharArrayReader is a character array input stream. It is similar to Bytearrayinputstream, except that Bytearrayinputstream is a byte array input stream, and Chararray is a character array input stream. CharArrayReader is used to read a character array, which inherits from reader. The data for the operation is in characters!
CharArrayReader Function List
CharArrayReader (char[] buf)
CharArrayReader (char[] buf, int offset, int length)
void Close ()
void mark (int readlimit)
boolean marksupported ()
int read ()
int read (char[] buffer, int offset, int len)
boolean ready ()
void Reset ()
long Skip (long charcount)
Reader and CharArrayReader source analysis
Reader is the chararrayreader of the parent class, we first look at the source code reader, and then learn CharArrayReader source code.
1. Reader source analysis (based on jdk1.7.40)
Package java.io;
Public abstract class Reader implements readable, closeable {protected Object lock;
Protected Reader () {this.lock = this;
} protected Reader (Object Lock) {if (lock = null) {throw new NullPointerException ();
} This.lock = lock;
public int read (Java.nio.CharBuffer target) throws IOException {int len = target.remaining ();
char[] Cbuf = new Char[len];
int n = read (cbuf, 0, Len);
if (n > 0) target.put (cbuf, 0, N);
return n;
public int read () throws IOException {char cb[] = new CHAR[1];
if (read (CB, 0, 1) = = 1) return-1;
else return cb[0];
public int read (char cbuf[]) throws IOException {return read (cbuf, 0, cbuf.length);
Abstract public int read (char cbuf[], int off, int len) throws IOException; Private static final int maxskipbuffersize = 8192;
Private char skipbuffer[] = null; Public long Skip (long N) throws IOException {if (n < 0L) throw new IllegalArgumentException ("Skip
Value is negative ");
int nn = (int) math.min (n, maxskipbuffersize); Synchronized (lock) {if (Skipbuffer = = null) | |
(Skipbuffer.length < NN))
Skipbuffer = new CHAR[NN];
Long r = N;
while (R > 0) {int NC = read (skipbuffer, 0, (int) math.min (r, nn));
if (NC = = 1) break;
R-= NC;
return n-r;
} public Boolean Ready () throws IOException {return false;
public boolean marksupported () {return false; public void mark (int readaheadlimit) throws IOException {throw new IOException ("Mark () not supported"
); } public void Reset () throws IOException {throw new IOException ("Reset () not supported");
Abstract public void Close () throws IOException; }