public PasswordAuthentication getAuthentication(String realm, URL tracker) { if (user_name == null || password == null) { String user_info = tracker.getUserInfo(); if (user_info == null) { return (null); } String user_bit = user_info; String pw_bit = ""; int pos = user_info.indexOf(':'); if (pos != -1) { user_bit = user_info.substring(0, pos); pw_bit = user_info.substring(pos + 1); } return (new PasswordAuthentication(user_bit, pw_bit.toCharArray())); } return (new PasswordAuthentication(user_name, password.toCharArray())); }
public static void main(String[] args) throws IOException { URL url = new URL("http://www.javajeff.com/articles/articles/html"); System.out.println("Authority = " + url.getAuthority()); System.out.println("Default port = " + url.getDefaultPort()); System.out.println("File = " + url.getFile()); System.out.println("Host = " + url.getHost()); System.out.println("Path = " + url.getPath()); System.out.println("Port = " + url.getPort()); System.out.println("Protocol = " + url.getProtocol()); System.out.println("Query = " + url.getQuery()); System.out.println("Ref = " + url.getRef()); System.out.println("User Info = " + url.getUserInfo()); }