java io进修(十) FilterOutputStream
FilterOutputStream 先容
FilterOutputStream 的浸染是用来“封装其它的输出流,并为它们提供特另外成果”。它主要包罗BufferedOutputStream, DataOutputStream和PrintStream。
(01) BufferedOutputStream的浸染就是为“输出流提供缓冲成果”。
(02) DataOutputStream 是用来装饰其它输出流,将DataOutputStream和DataInputStream输入流共同利用,“答允应用措施以与呆板无关方法从底层输入流中读写根基 Java 数据范例”。
(03) PrintStream 是用来装饰其它输出流。它能为其他输出流添加了成果,使它们可以或许利便地打印各类数据值暗示形式。
FilterOutputStream 源码(基于jdk1.7.40)
查察本栏目
package java.io; public class FilterOutputStream extends OutputStream { protected OutputStream out; public FilterOutputStream(OutputStream out) { this.out = out; } public void write(int b) throws IOException { out.write(b); } public void write(byte b[]) throws IOException { write(b, 0, b.length); } 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 { flush(); } catch (IOException ignored) { } out.close(); } }
来历:http://www.cnblogs.com/skywang12345/p/io_11.html