1 17 18 19 21 40 41 import java.io.*; import java.net.*; import java.util.*; 45 46 59 public class ExtractorURLStreamHandler extends URLStreamHandler { 60 61 69 public URLConnection openConnection( URL u ) 70 throws IOException 71 { 72 return new ExtractorURLConnection( u ); 73 } 74 75 99 protected void parseURL(URL u, String spec, int start, int limit) 100 { 101 System.out.println( "ExtractorURLStreamHandler.parseURL()" ); 102 103 String protocol = u.getProtocol(); 104 String host = u.getHost(); 105 int port = u.getPort(); 106 String file = u.getFile(); 107 String ref = u.getRef(); 108 109 String temp = spec.substring(start); 110 int i = temp.indexOf(":"); 111 if ( i >= 0 ) { 112 protocol = temp.substring( 0, i+1 ); 114 temp = temp.substring( i+1 ) ; 115 } 116 117 start=0; 118 if ( temp.charAt(start) == '/' ) 119 ++start; 120 i = temp.indexOf( "/", start ); 121 if ( i >= start ) { 122 host = temp.substring( start, i ); 124 start = i+1; 125 } 126 127 if ( temp.charAt(start) == '+' && temp.charAt(start+1) == '/' ) { 129 start += 2; 131 file = temp.substring( start ); 132 } 133 134 System.out.println( "protocol:" + protocol ); 135 System.out.println( "host:" + host ); 136 System.out.println( "file:" + file ); 137 setURL( u, protocol, host, port, file, ref ); 138 } 139 140 147 protected String toExternalForm(URL u) { 148 String result = u.getProtocol() + ":"; 149 if ((u.getHost() != null) && (u.getHost().length() > 0)) { 150 result = result + "/" + u.getHost(); 151 } 152 result += "/+/" + u.getFile(); 153 154 System.out.println( "ExtractorURLStreamHandler.toExternal() result:"+result ); 155 return result; 156 } 157 158 } 159 160 | Popular Tags |