01: package com.icesoft.faces.webapp.http.common.standard;
02:
03: import com.icesoft.faces.webapp.http.common.Response;
04: import com.icesoft.faces.webapp.http.common.ResponseHandler;
05:
06: import java.io.IOException;
07: import java.io.OutputStreamWriter;
08: import java.io.Writer;
09:
10: public abstract class StreamingContentHandler implements
11: ResponseHandler {
12: private String mimeType;
13: private String characterSet;
14:
15: protected StreamingContentHandler(String mimeType,
16: String characterSet) {
17: this .mimeType = mimeType;
18: this .characterSet = characterSet;
19: }
20:
21: public abstract void writeTo(Writer writer) throws IOException;
22:
23: public void respond(Response response) throws Exception {
24: response.setHeader("Content-Type", mimeType + "; charset="
25: + characterSet);
26: OutputStreamWriter writer = new OutputStreamWriter(response
27: .writeBody(), characterSet);
28: writeTo(writer);
29: writer.flush();
30: }
31: }
|