~/ learn/ comp-348/ cards/ Filter streams: chaining, buffering, and data streams
1 of 5

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

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/8bf1f006-eccc-40f3-8018-4c22af044adc/flashcard utf-8 LF