20-CS-694 Advanced Programming Techniques Spring 2012
Networking - Protocol Handler

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

     Previous      Next     Handler.java     CryptURLConnection.java     CryptInputStream.java     Rotate.java     ProtoTest.java      All lectures

Protocol Handler - Handler.java

This class file is placed in protocolhandlers/crypt.
package protocolhandlers.crypt;
import java.io.*;
import java.net.*;

public class Handler extends URLStreamHandler {
   protected void parseURL (URL url, String spec, int start, int end) {
      System.out.print("Handler: enter parseURL():\n  
		spec: ["+spec+"]\n  start: "+start+" end: "+end);
         int slash = spec.indexOf('/');
      String crypType = spec.substring(start, slash-1);
      System.out.println(" cryptType: ["+crypType+"]");
      super.parseURL (url, spec, slash, end);      
      super.setURL(url, "crypt:"+crypType, url.getHost(), 
         url.getPort(), url.getFile(), url.getRef());
      System.out.println("Handler: leave parseURL():\n  
         protocol:["+url.getProtocol()+"]\n  
		   Host:["+url.getHost()+"]\n  
         Port:["+url.getPort()+"]\n  
         File:["+url.getFile()+"]\n  
         Ref:["+url.getRef()+"]");
   }
   
   protected URLConnection openConnection (URL url) throws IOException {
      System.out.println("Handler: openConnection():");
      return new CryptURLConnection (url, "rotate");
   }
}