1 17 package org.eclipse.emf.common.archive; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.net.URL ; 22 import java.net.URLConnection ; 23 import java.net.URLStreamHandler ; 24 25 29 public class Handler extends URLStreamHandler 30 { 31 40 public static void register() 41 { 42 String javaProtocolHandlerPkgs = System.getProperty("java.protocol.handler.pkgs"); 43 if (javaProtocolHandlerPkgs == null || javaProtocolHandlerPkgs.length() == 0) 44 { 45 javaProtocolHandlerPkgs = "org.eclipse.emf.common"; 46 } 47 else 48 { 49 javaProtocolHandlerPkgs += "|org.eclipse.emf.common"; 50 } 51 System.setProperty("java.protocol.handler.pkgs", javaProtocolHandlerPkgs); 52 } 53 54 59 public static void main(String [] args) throws IOException 60 { 61 register(); 62 63 for (int i = 0; i < args.length; ++i) 64 { 65 InputStream inputStream = new URL (args[i]).openStream(); 66 byte [] bytes = new byte [4048]; 67 for (int size; (size = inputStream.read(bytes, 0, bytes.length)) > -1; ) 68 { 69 System.out.write(bytes, 0, size); 70 } 71 } 72 } 73 74 77 public Handler() 78 { 79 super(); 80 } 81 82 86 protected void parseURL(URL url, String specification, int start, int limit) 87 { 88 super.parseURL(url, specification, start, limit); 89 90 if (start > limit || specification.charAt(start) == '/') 93 { 94 throw 95 new IllegalArgumentException 96 ("archive protocol must be immediately followed by another URL protocol " + specification); 97 } 98 99 int archiveSeparator = specification.indexOf("!/", start); 102 if (archiveSeparator < 0) 103 { 104 throw new IllegalArgumentException ("missing archive separators " + specification.substring(start, limit)); 105 } 106 107 for (int i = start, end = specification.indexOf('/', start) - 1; (i = specification.indexOf(':', i)) < end; ++i) 110 { 111 archiveSeparator = specification.indexOf("!/", archiveSeparator + 2); 114 if (archiveSeparator < 0) 115 { 116 throw new IllegalArgumentException ("too few archive separators " + specification); 117 } 118 } 119 } 120 121 124 protected URLConnection openConnection(URL url) throws IOException 125 { 126 return new ArchiveURLConnection(url); 127 } 128 } 129 | Popular Tags |