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 | ||
13 | public abstract void respond(Request req, PrintWriter out); | |
14 | ||
15 | public void respond(Request req) { | |
16 | req.outheaders().put("Content-Type", "text/" + ctype + "; charset=utf-8"); | |
17 | PrintWriter out; | |
18 | try { | |
19 | out = new PrintWriter(new OutputStreamWriter(req.output(), "UTF-8")); | |
20 | } catch(UnsupportedEncodingException e) { | |
21 | throw(new Error(e)); | |
22 | } | |
23 | respond(req, out); | |
24 | out.flush(); | |
25 | } | |
26 | } |