文章目录
1、InputStream和OutputStream
public abstract class InputStream implements Closeable {
// MAX_SKIP_BUFFER_SIZE is used to determine the maximum buffer size to
// use when skipping.
private static final int MAX_SKIP_BUFFER_SIZE = 2048;
}
有上面内容可知,InputStream是一个抽象类实现了Closeable接口,,也间接实现了AutoCloseable接口,有一个成员变量MAX_SKIP_BUFFER_SIZE,用于确定跳过时使用的最大缓冲区大小
public abstract class OutputStream implements Closeable, Flushable {
}
由上面可知,OutputStream也是一个抽象类,实现了Closeable, Flushable接口,也间接实现了AutoCloseable接口
2、BufferedInputStream 和 BufferedOutputStream
BufferedInputStream 类的继承与实现关系及对应的成员变量、构造、方法
public class BufferedInputStream extends FilterInputStream {
// 默认缓冲大小
private static int DEFAULT_BUFFER_SIZE = 8192;
// 最大缓冲大小
private static int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
// 缓冲存储区
protected volatile byte buf[];
private static final
AtomicReferenceFieldUpdater<BufferedInputStream, byte[]> bufUpdater =
AtomicReferenceFieldUpdater.newUpdater
(BufferedInputStream.class, byte[].class, "buf");
protected int count;
protected int pos;
protected int markpos = -1;
protected int marklimit;
public BufferedInputStream(InputStream in) {
this(in, DEFAULT_BUFFER_SIZE);
}
public BufferedInputStream(InputStream in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
}
}
BufferedIOutputStream 类的继承与实现关系及对应的成员变量、构造、方法
public class BufferedOutputStream extends FilterOutputStream {
// 缓冲区大小
protected byte buf[];
protected int count;
public BufferedOutputStream(OutputStream out) {
this(out, 8192);
}
public BufferedOutputStream(OutputStream out, int size) {
super(out);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0"