package vicazh.hyperpool.stream.net.http.html;
import java.io.*;
import java.net.*;
import java.util.logging.*;
import vicazh.hyperpool.Start;
import vicazh.hyperpool.Writer;
import vicazh.hyperpool.stream.net.http.*;
import vicazh.hyperpool.stream.*;
class XMLClientStream extends ClientStream implements Runnable {
XMLClientStream(Session session) {
super(session, new NullStream());
}
public void run() {
synchronized (connection) {
try {
session.getServer().head("HTTP/1.1", ServerStream.OK, "");
session.getServer().field("Content-Type", "text/html");
session.getServer().field("Server",
Start.SYSTEM_NAME + "/" + Start.VERSION);
byte[] b = new Writer(getFile())
.get(((XMLService) connection.element).object);
session.getServer().field("Content-Length",
String.valueOf(b.length));
session.getServer().field("Connection", "close");
session.getServer().header();
connection.getServer().write(b);
connection.getServer().flush();
String c = getField("connection");
if (c != null && c.equalsIgnoreCase("close"))
connection.getServer().close();
return;
} catch (SocketException e) {
Start.logger.fine(e.getMessage());
} catch (SocketTimeoutException e) {
Start.logger.fine(e.getMessage());
} catch (UnknownHostException e) {
Start.logger.fine(e.getMessage());
} catch (BreakException e) {
} catch (Exception e) {
Start.logger.log(Level.SEVERE, e.getMessage(), e);
}
try {
connection.getServer().close();
} catch (Exception e) {
}
}
}
public void end() {
super.end();
if (getFile() != null)
new Thread(this).start();
}
public void close() throws IOException {
super.close();
new Thread() {
public void run() {
try {
connection.getServer().close();
} catch (Exception e) {
}
}
}.start();
}
}