Commit | Line | Data |
---|---|---|
79d2dd64 FT |
1 | package dolda.jsvc.util; |
2 | ||
3 | import dolda.jsvc.*; | |
4 | import java.io.*; | |
5 | ||
6 | public abstract class SimpleWriter implements Responder { | |
7 | private String ctype; | |
8 | ||
9 | public SimpleWriter(String ctype) { | |
10 | this.ctype = ctype; | |
11 | } | |
12 | ||
80e2f848 FT |
13 | public SimpleWriter() { |
14 | this("html"); | |
15 | } | |
16 | ||
79d2dd64 FT |
17 | public abstract void respond(Request req, PrintWriter out); |
18 | ||
19 | public void respond(Request req) { | |
20 | req.outheaders().put("Content-Type", "text/" + ctype + "; charset=utf-8"); | |
21 | PrintWriter out; | |
22 | try { | |
23 | out = new PrintWriter(new OutputStreamWriter(req.output(), "UTF-8")); | |
24 | } catch(UnsupportedEncodingException e) { | |
25 | throw(new Error(e)); | |
26 | } | |
27 | respond(req, out); | |
28 | out.flush(); | |
29 | } | |
30 | } |