| 1 23 package org.archive.net.md5; 24 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.net.URL ; 28 import java.net.URLConnection ; 29 import java.net.URLStreamHandler ; 30 31 53 public class Handler extends URLStreamHandler { 54 protected URLConnection openConnection(URL u) { 55 return new Md5URLConnection(u); 56 } 57 58 63 public static void main(String [] args) 64 throws IOException { 65 if (args.length != 1) { 66 System.out.println("Usage: java java " + 67 "-Djava.protocol.handler.pkgs=org.archive.net " + 68 "org.archive.net.md5.Handler " + 69 "md5:deadbeefdeadbeefdeadbeefdeadbeef"); 70 System.exit(1); 71 } 72 System.setProperty("org.archive.net.md5.Md5URLConnection.path", 73 "/tmp/manifest"); 74 System.setProperty("java.protocol.handler.pkgs", "org.archive.net"); 75 URL u = new URL (args[0]); 76 URLConnection connect = u.openConnection(); 77 final int bufferlength = 4096; 79 byte [] buffer = new byte [bufferlength]; 80 InputStream is = connect.getInputStream(); 81 try { 82 for (int count = is.read(buffer, 0, bufferlength); 83 (count = is.read(buffer, 0, bufferlength)) != -1;) { 84 System.out.write(buffer, 0, count); 85 } 86 System.out.flush(); 87 } finally { 88 is.close(); 89 } 90 } 91 } 92 | Popular Tags |