1 25 package org.archive.net.rsync; 26 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.net.URL ; 30 import java.net.URLConnection ; 31 import java.net.URLStreamHandler ; 32 33 43 public class Handler extends URLStreamHandler { 44 protected URLConnection openConnection(URL u) { 45 return new RsyncURLConnection(u); 46 } 47 48 53 public static void main(String [] args) 54 throws IOException { 55 if (args.length != 1) { 56 System.out.println("Usage: java java " + 57 "-Djava.protocol.handler.pkgs=org.archive.net " + 58 "org.archive.net.rsync.Handler RSYNC_URL"); 59 System.exit(1); 60 } 61 URL u = new URL (args[0]); 62 URLConnection connect = u.openConnection(); 63 final int bufferlength = 4096; 65 byte [] buffer = new byte [bufferlength]; 66 InputStream is = connect.getInputStream(); 67 try { 68 for (int count = is.read(buffer, 0, bufferlength); 69 (count = is.read(buffer, 0, bufferlength)) != -1;) { 70 System.out.write(buffer, 0, count); 71 } 72 System.out.flush(); 73 } finally { 74 is.close(); 75 } 76 } 77 } | Popular Tags |