##1.Writer
官方描述: 写入字符流的抽象类。子类必须实现的方法仅有 write(char[], int, int)、flush() 和 close()。但是,多数子类将重写此处定义的一些方法,以提供更高的效率和/或其他功能。
#####继承了三个接口
public abstract class Writer implements Appendable, Closeable, Flushable {
//缓存区 ,如欲写入String/CharSequence将使用该buffer
private char[] writeBuffer;
//默认的大小,如写入的String大于该缓冲区,则会新建相应大小的buffer
private static final int WRITE_BUFFER_SIZE = 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) {
//如果buffer未初始化,则初始化
if (writeBuffer == null){
writeBuffer = new char[WRITE_BUFFER_SIZE];
}
//将 写入的in