I understand the theory behind BufferedOutputStream
. Bytes are written to a buffer array until it is full, and then written (flushed) to the underlying stream - the idea being that it is faster than writing byte-by-byte as there are fewer OS calls.
However, from looking at the implementation of the BufferedOutputStream
class and methods (BufferedOutputStream.java), it seems that ultimately, the bytes from the buffer are just written byte-by-byte.
I think this is the case because:
In BufferedOutputStream.write(byte b[], int off, int len) it has the line out.write(b, off, len). Since out is an instance of OutputStream, but not BufferedOutputStream, it is calling OutputStream.write(byte[], int, int). This in turn uses a for loop to write byte-by-byte
Please could someone clarify what is actually going on, and how it is faster?