BufferedInputStream 明明源码实现里面是调用了传入的inputstream的read()函数,为什么说它有缓冲区更快?
private void fill() throws IOException {
byte[] buffer = getBufIfOpen();
if (markpos >= 0 && pos >= buffer.length) {
if (markpos > 0) {
int sz = pos - markpos;
System.arraycopy(buffer, markpos, buffer, 0, sz);
pos = sz;
markpos = 0;
}
}
count = pos;
int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
if (n > 0)
count = n + pos;
}
这里还是调用了read()函数,我看对于这个类的解释都是说一次从输入流里面读取了多个数据到内存中,如果就是其他的inputstream对象也能用read()函数完成这个功能为什么还要弄个缓冲区,再从缓存区里面读取,不是更慢吗