Java 日看一类(26)之IO包中的FilterReader类

该类无引入包

继承自Reader 类



类头注释如下:

/**
 * Abstract class for reading filtered character streams.
 * The abstract class <code>FilterReader</code> itself
 * provides default methods that pass all requests to
 * the contained stream. Subclasses of <code>FilterReader</code>
 * should override some of these methods and may also provide
 * additional methods and fields.
 *
 * @author      Mark Reinhold
 * @since       JDK1.1
 */

大意如下:

该类是个用于过滤读取字符流的抽象类

FilterReader提供了默认的方法将请求传递到其包含的底层流中

以该类作为基类的类需要覆写该类的一些方法,同时也可以提供一些额外的方法和参数



该类含有的成员变量如下:

字符输入流Reader

protected Reader in;




该类含有如下的成员方法:

构造函数(绑定输入流

protected FilterReader(Reader in) {
    super(in);
    this.in = in;
}

读取一个字符

public int read() throws IOException {
    return in.read();
}

将字符读入传入数组中(特定位置和长度,返回实际读取数

public int read(char cbuf[], int off, int len) throws IOException {
    return in.read(cbuf, off, len);
}

跳过数个字符(返回跳过字符数

public long skip(long n) throws IOException {
    return in.skip(n);
}

判断输入流是否可读取

public boolean ready() throws IOException {
    return in.ready();
}

判断该流是否支持标记操作

public boolean markSupported() {
    return in.markSupported();
}

在当前位置设立标记(传入的是最大回滚距离

public void mark(int readAheadLimit) throws IOException {
    in.mark(readAheadLimit);
}

回滚

public void reset() throws IOException {
    in.reset();
}

关闭当前流

public void close() throws IOException {
    in.close();
}




该类作为抽象类十分简单,功能也是简单调用了Reader类,大体结构和BufferedReader差不多,可以参考下


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值