01: package vicazh.hyperpool.stream.net.http.html;
02:
03: import vicazh.hyperpool.Start;
04: import vicazh.hyperpool.Writer;
05: import vicazh.hyperpool.stream.net.http.*;
06: import vicazh.hyperpool.stream.*;
07:
08: class XMLStream extends ClientStream implements Runnable {
09:
10: XMLStream(Session session) {
11: super (session, new NullStream());
12: }
13:
14: public void run() {
15: synchronized (connection) {
16: try {
17: session.getServer().head("HTTP/1.1", ServerStream.OK,
18: "");
19: session.getServer().field("Content-Type", "text/html");
20: session.getServer().field("Server",
21: Start.NAME + "/" + Start.VERSION);
22: byte[] b = new Writer(getFile())
23: .get(((XMLService) connection.element).object);
24: session.getServer().field("Content-Length",
25: String.valueOf(b.length));
26: session.getServer().field("Connection", "close");
27: session.getServer().header();
28: connection.getServer().write(b);
29: connection.getServer().flush();
30: String c = (String) getFields().get("connection");
31: if (c != null && c.equalsIgnoreCase("close"))
32: connection.getServer().close();
33: } catch (Exception e) {
34: try {
35: connection.getServer().flush();
36: } catch (Exception ex) {
37: }
38: try {
39: connection.getServer().close();
40: } catch (Exception ex) {
41: }
42: }
43: }
44: }
45:
46: public void end() {
47: super .end();
48: if (getFile() != null)
49: new Thread(this).start();
50: }
51: }
|