继承InputStream类
无引入包
类头注释如下
/** * A <code>FilterInputStream</code> contains * some other input stream, which it uses as * its basic source of data, possibly transforming * the data along the way or providing additional * functionality. The class <code>FilterInputStream</code> * itself simply overrides all methods of * <code>InputStream</code> with versions that * pass all requests to the contained input * stream. Subclasses of <code>FilterInputStream</code> * may further override some of these methods * and may also provide additional methods * and fields. * * @author Jonathan Payne * @since JDK1.0 */
大意如下:
FilterInputStream包含其他的输入的流
它将这些流作为基础数据源,它可以改变这个数据的格式或者提供其他的功能
FilterInputStream简单的覆写了那些将所有请求传输给包含的InputStream类的方法
以FilterInputStream作为基类的类可能会覆写更多的方法并且可能会会提供更多的功能和字段
该类含有如下的成员变量:
需要被过滤的输入流
protected volatile InputStream in;
该类含有如下的成员方法:
构造函数(少见的仅有一个构造函数的类
protected FilterInputStream(InputStream in) { this.in = in; }
从输入流中读取下一个byte数据(返回值为读取字节数
public int read() throws IOException { return in.read(); }
从输入流中读取传入数组大小的数据(读入到该数组中,返回值为读取字节数
public int read(byte b[]) throws IOException { return read(b, 0, b.length); }
从输入流中读取特定大小的数据写入到数组中(返回值为字节数
public int read(byte b[], int off, int len) throws IOException { return in.read(b, off, len); }
跳过后续n个byte进行读取(返回值为实际跳过byte数
public long skip(long n) throws IOException { return in.skip(n); }
返回流中可被直接读取(或跳过)的有效数据数(估计值)/返回下一次对此输入流调用的方法可以不受阻塞地从此输入流读取(或跳过)的估计剩余字节数。
public int available() throws IOException { return in.available(); }
关闭流,释放资源
public void close() throws IOException { in.close(); }
设置当前位置为标记点(传入参数为在当前标记点无效前最多可以读取的字节数(实际就是回滚缓存大小))
public synchronized void mark(int readlimit) { in.mark(readlimit); }
重置到标记点(类似回滚机制
public synchronized void reset() throws IOException { in.reset(); }
判断当前类是否支持标记回滚机制
public boolean markSupported() { return in.markSupported(); }
该类也十分简单,主体思路是扩充了函数种类,同时对InpuStream做了一个简单的实现和控制,(我的感觉这个类实际像是个接口,只不过做成了继承类的形式,毕竟不存在继承其他类的接口),主要方法都是调用InputStream中的方法实现。

本文详细介绍了FilterInputStream类,它是InputStream的子类,用于包装其他输入流并提供额外功能或转换数据。文章涵盖了其构造方法、成员变量及核心方法,如read、skip等。
387

被折叠的 条评论
为什么被折叠?



