自定义装饰类

来源:互联网 发布:辐射4 mac 下载 编辑:程序博客网 时间:2024/06/05 17:24
import java.io.*;class MyBufferedReader extends Reader {    private Reader r;    MyBufferedReader(Reader r) {        this.r = r;    }    public String myReadLine() throws IOException {        StringBuilder sb = new StringBuilder();        int ch = 0;        while ((ch = r.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;    }    public void myClose() throws IOException {        r.close();    }    /*     * 覆盖Reader类中的抽象方法。     */    public int read(char[] cbuf, int off, int len) throws IOException {        return r.read(cbuf, off, len);    }    public void close() throws IOException {        r.close();    }}
0 0