~/ 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/c05a9a72-839f-47a7-a581-a2bccab495fb/flashcard utf-8 LF