Chararraywriter Introduction
CharArrayReader is used to write the data character, which inherits from writer. The data for the operation is in characters!
Chararraywriter Function List
Chararraywriter ()
chararraywriter (int initialsize)
chararraywriter Append (charsequence csq, int start, int end)
chararraywriter append (char c)
chararraywriter append (charsequence csq)
void Close ()
void flush ()
void reset ()
int size ()
char[] ToCharArray ()
String toString ()
void write (char[] buffer, int offset, int len)
void write (int Onechar)
void write (String str, int offset, int count)
void WriteTo (Writer out)
Writer and Chararraywriter Source analysis
Writer is the chararraywriter of the parent class, we first look at the source of writer, and then learn Chararraywriter source code.
1. Writer Source analysis (based on jdk1.7.40)
Package java.io;
Public abstract class Writer implements Appendable, Closeable, flushable {private char[] writebuffer;
Private final int writebuffersize = 1024;
protected Object Lock;
Protected Writer () {this.lock = this;
} protected Writer (Object Lock) {if (lock = null) {throw new NullPointerException ();
} This.lock = lock; public void write (int c) throws IOException {synchronized (lock) {if (WriteBuffer = = nul
L) {writebuffer = new char[writebuffersize];
} Writebuffer[0] = (char) c;
Write (WriteBuffer, 0, 1);
} public void write (char cbuf[]) throws IOException {write (cbuf, 0, cbuf.length);
Abstract public void write (char cbuf[], int off, int len) throws IOException; public void Write (String str) throws IOException {write (s)TR, 0, Str.length ());
public void Write (String str, int off, int len) throws IOException {synchronized (lock) {
Char cbuf[]; if (len <= writebuffersize) {if (WriteBuffer = null) {WriteBuffer = new Char[wri
Tebuffersize];
} cbuf = WriteBuffer;
else {//Don ' t permanently allocate very large buffers.
Cbuf = new Char[len];
} str.getchars (off, (off + len), cbuf, 0);
Write (cbuf, 0, Len); } public Writer Append (charsequence csq) throws IOException {if (CSQ = null) write ("
Null ");
else Write (csq.tostring ());
return this; Writer Append (charsequence csq, int start, int end) throws IOException {Charsequence cs = (csq = null?
"NULL": CSQ);
Write (Cs.subsequence (start, end). toString ()); ReTurn this;
Public Writer Append (char c) throws IOException {write (c);
return this;
Abstract public void flush () throws IOException;
Abstract public void Close () throws IOException; }