Should I always wrap an InputStream as BufferedInputStream?

前端 未结 4 2183
感情败类
感情败类 2020-12-08 07:28

Does it make sense to always wrap an InputStream as BufferedInputStream, when I know whether the given InputStream is something other than buffered? For e.g:



        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 07:38

    It also depends on how you are going to read from the InputStream. If you are going to read it a character/byte at a time (ie read()), then the BufferedInputStream will reduce your overheads by queitly doing bulk reads on your behalf. If you are going to read it into a 4k or 8k byte/char array a block at a time then the BuffredInputStream probably won't benefit you.

提交回复
热议问题