home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
-
- public final class URL implements Serializable {
- private static final String protocolPathProp = "java.protocol.handler.pkgs";
- private String protocol;
- private String host;
- private int port;
- private String file;
- private String ref;
- transient URLStreamHandler handler;
- private int hashCode;
- static URLStreamHandlerFactory factory;
- static Hashtable handlers = new Hashtable();
-
- public URL(String var1, String var2, int var3, String var4) throws MalformedURLException {
- this.port = -1;
- this.hashCode = -1;
- this.protocol = var1;
- this.host = var2;
- this.port = var3;
- int var5 = var4.indexOf(35);
- this.file = var5 < 0 ? var4 : var4.substring(0, var5);
- this.ref = var5 < 0 ? null : var4.substring(var5 + 1);
- if ((this.handler = getURLStreamHandler(var1)) == null) {
- throw new MalformedURLException("unknown protocol: " + var1);
- }
- }
-
- public URL(String var1, String var2, String var3) throws MalformedURLException {
- this(var1, var2, -1, var3);
- }
-
- public URL(String var1) throws MalformedURLException {
- this((URL)null, var1);
- }
-
- public URL(URL var1, String var2) throws MalformedURLException {
- this.port = -1;
- this.hashCode = -1;
- String var3 = var2;
- int var7 = 0;
- String var8 = null;
- boolean var9 = false;
-
- try {
- int var5;
- for(var5 = var2.length(); var5 > 0 && var2.charAt(var5 - 1) <= ' '; --var5) {
- }
-
- while(var7 < var5 && var2.charAt(var7) <= ' ') {
- ++var7;
- }
-
- if (var2.regionMatches(true, var7, "url:", 0, 4)) {
- var7 += 4;
- }
-
- if (var7 < var2.length() && var2.charAt(var7) == '#') {
- var9 = true;
- }
-
- char var6;
- for(int var4 = var7; !var9 && var4 < var5 && (var6 = var2.charAt(var4)) != '/'; ++var4) {
- if (var6 == ':') {
- var8 = var2.substring(var7, var4).toLowerCase();
- var7 = var4 + 1;
- break;
- }
- }
-
- if (var1 == null || var8 != null && !var8.equals(var1.protocol)) {
- this.protocol = var8;
- } else {
- this.protocol = var1.protocol;
- this.host = var1.host;
- this.port = var1.port;
- this.file = var1.file;
- }
-
- if (this.protocol == null) {
- throw new MalformedURLException("no protocol: " + var3);
- } else if ((this.handler = getURLStreamHandler(this.protocol)) == null) {
- throw new MalformedURLException("unknown protocol: " + this.protocol);
- } else {
- int var13 = var2.indexOf(35, var7);
- if (var13 >= 0) {
- this.ref = var2.substring(var13 + 1, var5);
- var5 = var13;
- }
-
- this.handler.parseURL(this, var2, var7, var5);
- }
- } catch (MalformedURLException var11) {
- throw var11;
- } catch (Exception var12) {
- throw new MalformedURLException(var2 + ": " + var12);
- }
- }
-
- protected void set(String var1, String var2, int var3, String var4, String var5) {
- this.protocol = var1;
- this.host = var2;
- this.port = var3;
- this.file = var4;
- this.ref = var5;
- }
-
- public int getPort() {
- return this.port;
- }
-
- public String getProtocol() {
- return this.protocol;
- }
-
- public String getHost() {
- return this.host;
- }
-
- public String getFile() {
- return this.file;
- }
-
- public String getRef() {
- return this.ref;
- }
-
- public boolean equals(Object var1) {
- if (this.ref == null) {
- return var1 instanceof URL && this.sameFile((URL)var1);
- } else {
- return var1 instanceof URL && this.sameFile((URL)var1) && this.ref.equals(((URL)var1).ref);
- }
- }
-
- public int hashCode() {
- if (this.hashCode == -1) {
- this.hashCode = this.host.toLowerCase().hashCode() ^ this.file.hashCode() ^ this.protocol.hashCode();
- }
-
- return this.hashCode;
- }
-
- boolean hostsEqual(String var1, String var2) {
- if (var1.equals(var2)) {
- return true;
- } else {
- try {
- InetAddress var3 = InetAddress.getByName(var1);
- InetAddress var4 = InetAddress.getByName(var2);
- return var3.equals(var4);
- } catch (UnknownHostException var5) {
- } catch (SecurityException var6) {
- }
-
- return false;
- }
- }
-
- public boolean sameFile(URL var1) {
- return this.protocol.equals(var1.protocol) && this.hostsEqual(this.host, var1.host) && this.port == var1.port && this.file.equals(var1.file);
- }
-
- public String toString() {
- return this.toExternalForm();
- }
-
- public String toExternalForm() {
- return this.handler.toExternalForm(this);
- }
-
- public URLConnection openConnection() throws IOException {
- return this.handler.openConnection(this);
- }
-
- public final InputStream openStream() throws IOException {
- return this.openConnection().getInputStream();
- }
-
- public final Object getContent() throws IOException {
- return this.openConnection().getContent();
- }
-
- public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory var0) {
- if (factory != null) {
- throw new Error("factory already defined");
- } else {
- SecurityManager var1 = System.getSecurityManager();
- if (var1 != null) {
- var1.checkSetFactory();
- }
-
- handlers.clear();
- factory = var0;
- }
- }
-
- static synchronized URLStreamHandler getURLStreamHandler(String var0) {
- URLStreamHandler var1 = (URLStreamHandler)handlers.get(var0);
- if (var1 == null) {
- if (factory != null) {
- var1 = factory.createURLStreamHandler(var0);
- }
-
- if (var1 == null) {
- String var2 = System.getProperty("java.protocol.handler.pkgs", "");
- if (var2 != "") {
- var2 = var2 + "|";
- }
-
- var2 = var2 + "sun.net.www.protocol";
- StringTokenizer var3 = new StringTokenizer(var2, "|");
-
- while(var1 == null && var3.hasMoreTokens()) {
- String var4 = var3.nextToken().trim();
-
- try {
- String var5 = var4 + "." + var0 + ".Handler";
- var1 = (URLStreamHandler)Class.forName(var5).newInstance();
- } catch (Exception var6) {
- }
- }
- }
-
- if (var1 != null) {
- handlers.put(var0, var1);
- }
- }
-
- return var1;
- }
-
- private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
- var1.defaultWriteObject();
- }
-
- private synchronized void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
- var1.defaultReadObject();
- if ((this.handler = getURLStreamHandler(this.protocol)) == null) {
- throw new IOException("unknown protocol: " + this.protocol);
- }
- }
- }
-