FileDocCategorySizeDatePackage
ProtocolTester.javaAPI DocExample1126Thu Apr 03 15:27:30 BST 1997None

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(args[0]);
      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);
    }