FileDocCategorySizeDatePackage
ProtocolTester.javaAPI DocExample1169Wed Jul 03 22:04:56 BST 2002None

ProtocolTester

public class ProtocolTester extends Object implements URLStreamHandlerFactory

Fields Summary
String
theURL
Constructors Summary
public ProtocolTester(String s)

  
    theURL = s;
    
  
Methods Summary
public java.net.URLStreamHandlercreateURLStreamHandler(java.lang.String protocol)

  
    protocol = protocol.toLowerCase();    
    try {
      Class ph = Class.forName(protocol + "URLStreamHandler");
      Object o = ph.newInstance();
      return (URLStreamHandler) o;    
    }
    catch (Exception e) {
      return null;
    }
    
  
public static voidmain(java.lang.String[] args)

  
    
    
    //if (args.length == 1) {
      ProtocolTester pt = new ProtocolTester("http://www.chrisbibby.org.uk");
      URL.setURLStreamHandlerFactory(pt);
      pt.test();
    //}
    
    //else {
      //System.err.println("Usage: java ProtocolTester url"); 
    //}
  
  
public voidtest()

  
    String theLine;
  
    try {
      URL u = new URL(theURL);
      DataInputStream dis = new DataInputStream(u.openStream());
      while ((theLine = dis.readLine()) != null) {
        System.out.println(theLine);
      }
    }
    catch (IOException e) {
      System.err.println(e);
    }