We break down why copying “byte by byte” via
read()/
write() is usually slow, how “our” buffer
ByteArray differs from the wrappers
BufferedInputStream/
BufferedOutputStream, what the contract of
read(buffer) is (the value
n and
-1 at EOF), and what the canonical chunk-copy loop with
output.write(buffer, 0, n) looks like. At the end: choosing a buffer size, a data-flow diagram (mermaid), and common mistakes.