The copy loop: read into a buffer, write only what arrived
The copy loop: read into a buffer, write only what arrived
Answer
byte[] buf = new byte[8192]; int count; while ((count = in.read(buf)) != -1) { out.write(buf, 0, count); } out.flush();
The three-argument write is the whole point: writing buf without the count would send 8,192 bytes every pass, padding the output with stale bytes from the previous read. This loop is how every file and every response body in the course gets copied.
Harold 4e ch2 §Input Streams