该类继承自OutputStream类
无引入包
类头注释如下:
/** * This class is the superclass of all classes that filter output * streams. These streams sit on top of an already existing output * stream (the <i>underlying</i> output stream) which it uses as its * basic sink of data, but possibly transforming the data along the * way or providing additional functionality. * <p> * The class <code>FilterOutputStream</code> itself simply overrides * all methods of <code>OutputStream</code> with versions that pass * all requests to the underlying output stream. Subclasses of * <code>FilterOutputStream</code> may further override some of these * methods as well as provide additional methods and fields. * * @author Jonathan Payne * @since JDK1.0 */
大意如下:
这个类是所有过滤输出流类的祖先
这些流位于所有已存在的输出流(底层输出流)之上,使用基础类型的数据
但也可能改变数据的类型或者提供一些额外的方法
FilterOutputStream类对那些将所有请求都传递给底层输出流的OutputStream方法做了简单的覆写
以该类作为基类的类可能会覆写该类的方法并且提供额外的方法和参数
该类含有如下成员变量:
该类的底层输出流
protected OutputStream out;
该类含有如下的成员方法:
构造方法(过滤传入的输出流
public FilterOutputStream(OutputStream out) { this.out = out; }
写出一个字节
public void write(int b) throws IOException { out.write(b); }
写出一个byte数组
public void write(byte b[]) throws IOException { write(b, 0, b.length); }
写出该byte数组中特定位置和长度的数据
public void write(byte b[], int off, int len) throws IOException { if ((off | len | (b.length - (len + off)) | (off + len)) < 0) throw new IndexOutOfBoundsException(); for (int i = 0 ; i < len ; i++) { write(b[off + i]); } }
刷新输出流(将输出流中的数据输出
public void flush() throws IOException { out.flush(); }
关闭输出流(关闭前先讲输出流中的数据写出
public void close() throws IOException { try (OutputStream ostream = out) { flush(); } }
该类仅做了一些简单的覆写,主体还是OutputStream,大概看看就行,主要关注子类

本文介绍了FilterOutputStream类,它是所有过滤输出流类的超类。此类继承自OutputStream类,并为子类提供了一个基本的数据输出方式,同时允许子类进一步覆盖方法及提供额外的功能。
246

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



