FileDocCategorySizeDatePackage
daytimeURLConnection.javaAPI DocExample1103Thu Apr 03 15:27:06 BST 1997None

daytimeURLConnection

public class daytimeURLConnection extends URLConnection

Fields Summary
Socket
theConnection
public static final int
defaultPort
Constructors Summary
public daytimeURLConnection(URL u)


      
    super(u);
  
Methods Summary
public synchronized voidconnect()

  
    int port;
  
    if (!connected) {
      port = url.getPort();
      if ( port < 0) {
        port = defaultPort;
      }
      theConnection = new Socket(url.getHost(), port);
      connected = true;
    } 
  
  
public java.lang.ObjectgetContent()

    return getInputStream();
  
public java.lang.StringgetContentType()

    return "text/html";
  
public synchronized java.io.InputStreamgetInputStream()

  
    if (!connected) {
      connect();
    }
    DataInputStream dis = new DataInputStream(theConnection.getInputStream());
    String time = dis.readLine();
    String html = "<html><head><title>The Time at " +
      url.getHost() + "</title></head><body><h1>" +
      time + "</h1></body></html>";
      
    return new StringBufferInputStream(html);