import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 *	模拟字符流缓冲区 readline()
 *	装饰模式
 * @author WangShuang
 *
 */
public class Demo {

	public static void main(String[] args) {
		MyBufferedReader my = null;
		try {
			FileReader	fr = new FileReader("c:\\字符流缓冲区.txt");
			 my =  new MyBufferedReader(fr);
			String buff = null;
			while((buff = my.myReadLine())!=null){
				System.out.println(buff);
			}
		} catch (Exception e) {
			throw new RuntimeException("读取错误");
		}finally {
			try {
				if(my!=null)
					my.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		
	}
}
class MyBufferedReader extends Reader {
	Reader in = null;
	public MyBufferedReader(Reader in) {
		this.in = in;
	}
	//增强的方法
	public String myReadLine() throws IOException{
		StringBuffer sb = new StringBuffer();
		int ch = 0;
		while((ch = in.read())!=-1){
			if(ch == '\r')
				continue;
			if(ch== '\n')
				return sb.toString();
			else
				sb.append((char)ch);
		}
		if(sb.length()!=0){
			return sb.toString();
		}
		return null;
	}
	@Override
	public int read(char[] cbuf, int off, int len) throws IOException {
		return in.read(cbuf, off, len);
	}
	@Override
	public void close() throws IOException {
		in.close();
		
	}
	
}