1

When you use the method write(byte[] b) to write to a BufferedOutputStream, the write method from FilterOutputStream is used. The documentation says:

"The write method of FilterOutputStream calls its write method of three arguments with the arguments b, 0, and b.length. "

Which write method with three arguments is it referring to? The one in FilterOutputStream, or the one in BufferedOutputStream? (i.e. is the write actually buffered?).

I believe it is, but I'm not sure.

4

2 回答 2

1

BufferedOutputStream overrides the write(byte[], int, int) method, so that new override is called. Yes, the write is buffered.

于 2012-02-14T19:00:28.487 回答
1

答案是肯定的和否定的。总结一下我的发现:有效结果与承诺(“缓冲”)略有不同,因为是否立即刷新流取决于缓冲区的大小和每次调用存储的数据量。

以下来自更详细的http://docs.oracle.com/javase/7/docs/api/java/io/BufferedOutputStream.html(强调我自己的):

将指定字节数组中的 len 个字节从 offset off 处开始写入此缓冲输出流

通常,此方法将给定数组中的字节存储到此流的缓冲区中,并根据需要将缓冲区刷新到底层输出流。但是,如果请求的长度至少与此流的缓冲区一样大,则此方法将刷新缓冲区并将字节直接写入底层输出流。因此冗余的 BufferedOutputStreams 不会不必要地复制数据。

于 2012-02-14T19:06:32.360 回答