~/ learn/ comp-348/ cards/ Serving many files: media types and binary output
1 of 5

Two views of one socket: the raw stream and a Writer over it

Two views of one socket: the raw stream and a Writer over it

Answer

OutputStream raw = new BufferedOutputStream(client.getOutputStream()); Writer out = new OutputStreamWriter(raw, StandardCharsets.US_ASCII); Reader in = new InputStreamReader( new BufferedInputStream(client.getInputStream()), StandardCharsets.US_ASCII);

The `Writer` wraps `raw`, so both write into the same buffer and the same socket — there is one destination, not two. Both charsets are pinned to US-ASCII because request lines and response headers are protocol text, and protocol text is never platform-dependent.

Harold 4e ch9 §A Full-Fledged HTTP Server; ch2 §Readers and Writers

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/87802cbf-ef29-4cc7-adf5-2b2143f80941/flashcard utf-8 LF