Build a three-deep output chain over a socket
Build a three-deep output chain over a socket
Answer
OutputStream raw = socket.getOutputStream(); DataOutputStream out = new DataOutputStream(new BufferedOutputStream(raw)); out.writeInt(payload.length); out.write(payload); out.flush();
Constructors do the wiring, innermost argument first. writeInt lays down four big-endian bytes, the buffer keeps the header and body in one segment, and out is the only reference you keep or close.
Harold 4e ch2 §Filter Streams