Question

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.

Was it helpful?

Solution

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

OTHER TIPS

The answer is both yes and no. To summarize my finds: the effective result is a little different than what the promise ("buffered") because whether the stream is flushed immediately depends both on the size of the buffer and in the amount of data you store per call.

The following is from the somewhat more detailed http://docs.oracle.com/javase/7/docs/api/java/io/BufferedOutputStream.html (emphasis my own):

Writes len bytes from the specified byte array starting at offset off to this buffered output stream.

Ordinarily this method stores bytes from the given array into this stream's buffer, flushing the buffer to the underlying output stream as needed. If the requested length is at least as large as this stream's buffer, however, then this method will flush the buffer and write the bytes directly to the underlying output stream. Thus redundant BufferedOutputStreams will not copy data unnecessarily.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top