BufferedOutputStream vs ByteArrayOutputStream

后端 未结 3 1655
你的背包
你的背包 2021-02-07 02:15

Is there any advantage in wrapping a BufferedOutputStream around a ByteArrayOutputStream instead of just using the ByteArrrayOutputStream by itself?

3条回答
  •  鱼传尺愫
    2021-02-07 02:29

    Generally BufferedOutputStream wrapper is mostly used to avoid frequent disk or network writes. It can be much more expensive to separately write a lot of small pieces than make several rather large operations. The ByteArrayOutputStream operates in memory, so I think the wrapping is pointless.

    If you want to know the exact answer, try to create a simple performance-measuring application.

提交回复
热议问题