BufferedInputStream 明明源码实现里面是调用了传入的inputstream的read()函数,为什么说它有缓冲区更快?

sinat_35530444 2017-10-03 07:47:19
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()函数完成这个功能为什么还要弄个缓冲区,再从缓存区里面读取,不是更慢吗
...全文
112 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,626

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧