01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.net.*;
05: import java.net.Socket;
06: import vicazh.hyperpool.stream.net.*;
07: import vicazh.hyperpool.stream.net.Stream;
08:
09: class HttpStream extends ClientStream {
10:
11: HttpStream(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 = new URL(file);
18: if (outputstream == null
19: || !((HttpConnection) connection).authority.equals(url
20: .getAuthority())) {
21: if (outputstream != null) {
22: synchronized (connection) {
23: if (((Connection) connection).getSessions().size() > 1)
24: try {
25: connection.wait();
26: } catch (InterruptedException e) {
27: }
28: }
29: connection.getServer().outputstream = null;
30: connection.setServer(new Stream(
31: (Connection) connection, session.getServer()));
32: outputstream.flush();
33: outputstream.close();
34: ((HttpConnection) connection).socket.close();
35: }
36: ((HttpConnection) connection).authority = url
37: .getAuthority();
38: int i = url.getPort();
39: ((HttpConnection) connection).socket = new Socket(url
40: .getHost(), i == -1 ? url.getDefaultPort() : i);
41: ((HttpConnection) connection).socket
42: .setSoTimeout(((HttpService) connection.element).timeout);
43: outputstream = new BufferedOutputStream(
44: ((HttpConnection) connection).socket
45: .getOutputStream());
46: super .head(method, url.getFile(), version);
47: Transfer.start(new BufferedInputStream(
48: ((HttpConnection) connection).socket
49: .getInputStream()), session.connection
50: .getServer());
51: } else
52: super .head(method, url.getFile(), version);
53: }
54:
55: public vicazh.hyperpool.stream.net.Socket getSocket() {
56: return new vicazh.hyperpool.stream.net.Socket(
57: ((HttpConnection) connection).socket);
58: }
59:
60: }
|