01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.net.*;
05: import vicazh.hyperpool.stream.*;
06: import vicazh.hyperpool.stream.net.Stream;
07: import vicazh.hyperpool.stream.Selector;
08:
09: class ProtocolStream extends ClientStream {
10:
11: ProtocolStream(Session session, OutputStream outputstream) {
12: super (session, outputstream);
13: }
14:
15: public void head(String method, String file, String version)
16: throws IOException {
17: URL url;
18: try {
19: url = new URL(file);
20: } catch (MalformedURLException e) {
21: url = new URL("https://" + file);
22: }
23: int index = ((ListSelectorMBean) connection.element)
24: .getIndex(url.getProtocol());
25: if (outputstream == null
26: || ((ProtocolConnection) connection).index != index) {
27: if (outputstream != null) {
28: synchronized (connection) {
29: if (((Connection) connection).getSessions().size() > 1)
30: try {
31: connection.wait();
32: } catch (InterruptedException e) {
33: }
34: }
35: connection.getServer().outputstream = null;
36: connection.setServer(new Stream(
37: (Connection) connection, session.getServer()));
38: outputstream.flush();
39: outputstream.close();
40: }
41: ((ProtocolConnection) connection).index = index;
42: outputstream = ((Selector) connection.element).get(
43: connection.getServer(), index);
44: }
45: super.head(method, file, version);
46: }
47: }
|