FileDocCategorySizeDatePackage
DaytimeURLConnection.javaAPI DocExample1262Sun Dec 12 10:55:36 GMT 2004com.macfaq.net.www.protocol.daytime

DaytimeURLConnection

public class DaytimeURLConnection extends URLConnection

Fields Summary
private Socket
connection
public static final int
DEFAULT_PORT
Constructors Summary
public DaytimeURLConnection(URL u)


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

  
    if (!connected) {
      int port = url.getPort();
      if ( port <= 0 || port > 65535) {
        port = DEFAULT_PORT;
      }
      this.connection = new Socket(url.getHost(), port);
      this.connected = true;
    } 
  
public java.lang.StringgetContentType()

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

  
    if (!connected)  connect();

    String header = "<html><head><title>The Time at " 
     + url.getHost() + "</title></head><body><h1>";
    String footer = "</h1></body></html>";
    InputStream in1 = new ByteArrayInputStream(header.getBytes("8859_1"));  
    InputStream in2 = this.connection.getInputStream();  
    InputStream in3 = new ByteArrayInputStream(footer.getBytes("8859_1")); 
    
    SequenceInputStream result = new SequenceInputStream(in1, in2);
    result = new SequenceInputStream(result, in3); 
    return result;