Package vicazh.hyperpool.stream.net.http

Source Code of vicazh.hyperpool.stream.net.http.HttpStream

package vicazh.hyperpool.stream.net.http;

import java.io.*;
import java.net.*;
import java.net.Socket;
import vicazh.hyperpool.stream.net.*;

class HttpStream extends ClientStream {

  HttpStream(Session session, OutputStream outputstream) {
    super(session, outputstream);
  }

  public void head(String method, String file, String version)
      throws IOException {
    try {
      URL url = new URL(file);
      if (outputstream == null
          || !((HttpConnection) connection).authority.equals(url
              .getAuthority())) {
        if (outputstream != null) {
          reconnect();
          ((HttpConnection) connection).socket.close();
        }
        ((HttpConnection) connection).authority = url.getAuthority();
        int i = url.getPort();
        ((HttpConnection) connection).socket = new Socket(
            url.getHost(), i == -1 ? url.getDefaultPort() : i);
        ((HttpConnection) connection).socket
            .setSoTimeout(method.equalsIgnoreCase(ClientStream.GET)
                || method.equalsIgnoreCase(ClientStream.HEAD) ? ((HttpService) connection.element).timeoutShort
                : ((HttpService) connection.element).timeout);
        Transfer.start(new BufferedInputStream(
            ((HttpConnection) connection).socket.getInputStream()),
            connection.getServer());
        outputstream = new BufferedOutputStream(
            ((HttpConnection) connection).socket.getOutputStream());
      }
      super.head(method, url.getFile(), version);
    } catch (IOException e) {
      try {
        connection.getServer().close();
      } catch (Exception e1) {
      }
      throw e;
    }
  }

  public vicazh.hyperpool.stream.net.Socket getSocket() {
    return new vicazh.hyperpool.stream.net.Socket(
        ((HttpConnection) connection).socket);
  }

}
TOP

Related Classes of vicazh.hyperpool.stream.net.http.HttpStream

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.