Module java.base
Package java.io

Class FilterReader

java.lang.Object
java.io.Reader
java.io.FilterReader
所有已实现的接口:
Closeable, AutoCloseable, Readable
直接已知的子类:
PushbackReader

public abstract class FilterReader extends Reader
用于读取过滤字符流的抽象类。抽象类FilterReader本身提供了将所有请求传递给包含流的默认方法。 FilterReader的子类应该覆盖其中一些方法,还可以提供其他方法和字段。
自 JDK 版本:
1.1
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Reader
    in
    底层字符输入流。

    Fields declared in class java.io.Reader

    lock
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    创建一个新的过滤读取器。
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close()
    关闭流并释放与其关联的任何系统资源。
    void
    mark(int readAheadLimit)
    在流中标记当前位置。
    boolean
    告知此流是否支持mark()操作。
    int
    read()
    读取单个字符。
    int
    read(char[] cbuf, int off, int len)
    将字符读入数组的一部分。
    boolean
    ready()
    告知此流是否准备好进行读取。
    void
    reset()
    重置流。
    long
    skip(long n)
    跳过字符。

    Methods declared in class java.io.Reader

    nullReader, read, read, transferTo

    Methods declared in class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • in

      protected Reader in
      底层字符输入流。
  • Constructor Details

    • FilterReader

      protected FilterReader(Reader in)
      创建一个新的过滤读取器。
      参数:
      in - 提供底层流的 Reader 对象。
      抛出:
      NullPointerException - 如果 innull
  • Method Details

    • read

      public int read() throws IOException
      读取单个字符。
      覆盖:
      read 在类中 Reader
      返回:
      读取的字符,作为范围在 0 到 65535(0x00-0xffff)之间的整数,如果已到达流的末尾,则返回 -1
      抛出:
      IOException - 如果发生 I/O 错误
    • read

      public int read(char[] cbuf, int off, int len) throws IOException
      将字符读入数组的一部分。此方法将阻塞,直到有一些输入可用,发生 I/O 错误,或者到达流的末尾。

      如果 len 为零,则不会读取任何字符,并返回 0;否则,将尝试读取至少一个字符。如果由于流已到达其末尾而没有字符可用,则返回值为 -1;否则,将读取至少一个字符并存储到 cbuf 中。

      指定者:
      read 在类中 Reader
      参数:
      cbuf - 目标缓冲区
      off - 开始存储字符的偏移量
      len - 要读取的最大字符数
      返回:
      读取的字符数,如果已到达流的末尾,则返回 -1
      抛出:
      IndexOutOfBoundsException - 如果 off 为负数,或者 len 为负数,或者 len 大于 cbuf.length - off
      IOException - 如果发生 I/O 错误
    • skip

      public long skip(long n) throws IOException
      跳过字符。此方法将阻塞,直到有一些字符可用,发生 I/O 错误,或者到达流的末尾。如果在调用此方法之前流已到达其末尾,则不会跳过任何字符,并返回零。
      覆盖:
      skip 在类中 Reader
      参数:
      n - 要跳过的字符数
      返回:
      实际跳过的字符数
      抛出:
      IllegalArgumentException - 如果 n 为负数,并且包含的 Readerskip 方法对于负参数抛出 IllegalArgumentException
      IOException - 如果发生 I/O 错误
    • ready

      public boolean ready() throws IOException
      告知此流是否准备好进行读取。
      覆盖:
      ready 在类中 Reader
      返回:
      如果下一个 read() 不会阻塞以获取输入,则为 true,否则为 false。请注意,返回 false 不保证下一个读取将阻塞。
      抛出:
      IOException - 如果发生 I/O 错误
    • markSupported

      public boolean markSupported()
      告知此流是否支持 mark() 操作。
      覆盖:
      markSupported 在类中 Reader
      返回:
      如果此流支持 mark 操作,则为 true。
    • mark

      public void mark(int readAheadLimit) throws IOException
      在流中标记当前位置。
      覆盖:
      mark 在类中 Reader
      参数:
      readAheadLimit - 可读取的字符数限制。读取此数量的字符后,尝试重置流可能失败。
      抛出:
      IOException - 如果发生 I/O 错误
    • reset

      public void reset() throws IOException
      重置流。
      覆盖:
      reset 在类中 Reader
      抛出:
      IOException - 如果发生 I/O 错误
    • close

      public void close() throws IOException
      从类中复制的描述: Reader
      关闭流并释放与其关联的任何系统资源。一旦关闭流,进一步的 read()、ready()、mark()、reset() 或 skip() 调用将抛出 IOException。关闭先前关闭的流不会产生任何效果。
      指定者:
      close 在接口中 AutoCloseable
      指定者:
      close 在接口中 Closeable
      指定者:
      close 在类中 Reader
      抛出:
      IOException - 如果发生 I/O 错误