您的位置:首页 > 编程语言 > Java开发

Java 日看一类(25)之IO包中的FilterOutputStream类

2018-03-16 14:46 441 查看
该类继承自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,大概看看就行,主要关注子类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: