Java IO 之 OutputStream源码.docVIP

  • 3
  • 0
  • 约1.15千字
  • 约 3页
  • 2017-08-27 发布于湖北
  • 举报
Java IO 之 Outpu JDK1.0中就有了这传统的IO字节流,也就是 Inpu和java.io.Flushable两个接口。其中空实现了flush方法,即拥有刷新缓存区字节数组作用。 那些输出目标呢?比如: 1) 字节数组(不代表String类,但可以转换) 2) 文件 3) 管道(多线程环境中的数据源) 等等 FilterOutputStream是为各种OutputStream实现类提供的“装饰器模式”的基类。将属性或者有用的接口与输出流连接起来。 细解OutputStream源码的核心 一样的,先看源码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 /** ?* 所有字节输出流实现类的基类 ?*/ public abstract class SOutpu; ????} ?? ????// 将指定的byte数组中从偏移量off开始的len个字节写入输出流 ????public void write(byte b[], int off, int len) throws IOException { ????????if(b == null) { ????????????throw new NullPointerException(); ????????} elseif((off 0) || (off b.length) || (len 0) || ???????????????????((off + len) b.length) || ((off + len) 0)) { ????????????throw new IndexOutOfBoundsException(); ????????} elseif(len == 0) { ????????????return; ????????} ????????for(int i = 0; i len ; i++) { ????????????write(b[off + i]); ????????} ????} ?? ????// 刷新输出流,并强制写出所有缓冲的输出字节 ????public void flush() throws IOException { ????} ?? ????// 关闭输出流,并释放与该流有关的所有资源 ????public void close() throws IOException { ????} ?? } 其中三个核心的write()方法,对应着三个Inpu 或 四川华迪信息

文档评论(0)

1亿VIP精品文档

相关文档