java基础——java I/O学习笔记2
2017-10-17 21:59
204 查看
转自http://blog.csdn.net/qq924862077/
超类InputStream,是所有以字节输入流类的公共父类
JDK1.8中InputStream.java源码如下:
超类InputStream,是所有以字节输入流类的公共父类
JDK1.8中InputStream.java源码如下:
package java.io;
public abstract class InputStream implements Closeable { //最大跳过的缓冲区大小 private static final int MAX_SKIP_BUFFER_SIZE = 2048; //从输入的流中读取下一个字节 public abstract int read() throws IOException; //从输入流中读取一定大小的字节,没有数据返回-1 public int read(byte b[]) throws IOException { return read(b, 0, b.length); } //从输人流中读取的数据放到b数组中起始位置为off,长度为len 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) {} //返回到最近标记的位置 public synchronized void reset() throws IOException { throw new IOException("mark/reset not supported"); } //测试这个输入流是否支持标记或者重置方法 public boolean markSupported() { return false; } }
相关文章推荐
- 整理JAVA学习笔记 JAVA基础需要掌握重点
- Java2核心技术第七版的学习笔记(三) Fundamental Programming Structures in Java(Java语言的基础)(二)
- Java学习笔记(八、数据库编程基础)
- Java学习笔记(三、面向对象编程基础)
- java面试基础题,学习笔记!
- 很不错的JAVA学习笔记-Java基础-Java-编程开发
- java学习笔记,关于java的一些基础知识,适用于初学者,第一节
- 分布计算环境学习笔记5——Java Enterprise Edtion基础
- 传智博客学习笔记16--JAVA SCRIPT HTML语言基础
- Java基础学习笔记
- Java学习笔记基础篇(二)
- 传智播客_张孝祥_Java基础4_面向对象下_学习笔记
- 传智博客学习笔记4--JAVA编程基础1
- JAVA语言学习笔记之JAVA语言基础
- Java学习笔记(一、Java语言基础)
- Java基础学习笔记
- Java 基础学习笔记(持续更新中)
- [转]CoreJava学习笔记_Java语法基础
- java基础学习笔记原始类型变量赋值与非原始变量赋值
- Java学习笔记(七、网络编程基础)