InputStream 源码阅读
来源:互联网 发布:谁人知歌词 编辑:程序博客网 时间:2024/05/17 09:27
//表示所有字节输入流实现类的基类。它的作用就是抽象地表示所有从不同数据源产生输入的类public abstract class InputStream implements Closeable { private static final int MAX_SKIP_BUFFER_SIZE = 2048; // 从输入流中读取数据的下一个字节,以int返回 public abstract int read() throws IOException; // 从输入流中读取数据的一定数量字节,并存储在缓存数组b public int read(byte b[]) throws IOException { return read(b, 0, b.length); } // 从输入流中读取数据最多len个字节,并存储在缓存数组b public int read(byte b[], int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int c = read(); if (c == -1) { return -1; } b[off] = (byte)c; int i = 1; try { for (; i < len ; i++) { c = read(); if (c == -1) { break; } b[off + i] = (byte)c; } } catch (IOException ee) { } return i;//返回读取的字节数 } // 从输入流中跳过并丢弃 n 个字节的数据 public long skip(long n) throws IOException { long remaining = n; int nr; if (n <= 0) { return 0; } int size = (int)Math.min(MAX_SKIP_BUFFER_SIZE, remaining); byte[] skipBuffer = new byte[size]; while (remaining > 0) { nr = read(skipBuffer, 0, (int)Math.min(size, remaining)); if (nr < 0) { break; } remaining -= nr; } return n - remaining;//实际跳过的字节数 } // 返回下一个方法调用能不受阻塞地从此读取(或者跳过)的估计字节数 public int available() throws IOException { return 0; } // 关闭此输入流,并释放与其关联的所有资源 public void close() throws IOException {} // 在此输出流中标记当前位置 public synchronized void mark(int readlimit) {} // 将此流重新定位到最后一次对此输入流调用 mark 方法时的位置 public synchronized void reset() throws IOException { throw new IOException("mark/reset not supported"); } // 测试此输入流是否支持 mark 和 reset 方法 public boolean markSupported() { return false; }}
0 0
- InputStream 源码阅读
- Jdk8源码阅读之InputStream
- 走进源码之InputStream
- Java IO 之 InputStream源码
- Java8 I/O源码-InputStream
- 从JDK源码看InputStream
- 从JDK源码看InputStream
- 从JDK源码看InputStream
- 阅读源码
- 阅读源码
- 阅读源码
- 源码阅读
- JDK中java.io.InputStream源码
- JAVA IO源码学习系列之InputStream
- InputStream
- InputStream
- InputStream
- Inputstream
- Android开发-Json(一)Json数据的生成-完整Demo-AndroidStuidio
- HDU 4907 Task schedule(二分算法)
- 下拉菜单制作
- 最长公共子串(1)--hdu1238(多个字符串得最长公共子串--暴力)
- 中文乱码问题
- InputStream 源码阅读
- Java的接口和抽象类
- js数组操作
- leetcode_c++:树: Path SumII(113)
- Ubuntu 14.04 for Caffe 环境搭建
- 灰色关联度分析
- Spring Boot:在Eclipse/STS设置热插拔免重启
- 深入理解G1垃圾收集器
- Android一面而就最全面试题汇总