1 /* |
1 /* |
2 * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
40 protected java.net.URLConnection openConnection(URL u) |
39 protected java.net.URLConnection openConnection(URL u) |
41 throws IOException { |
40 throws IOException { |
42 return new JarURLConnection(u, this); |
41 return new JarURLConnection(u, this); |
43 } |
42 } |
44 |
43 |
45 private int indexOfBangSlash(String spec) { |
44 private static int indexOfBangSlash(String spec) { |
46 int indexOfBang = spec.length(); |
45 int indexOfBang = spec.length(); |
47 while((indexOfBang = spec.lastIndexOf('!', indexOfBang)) != -1) { |
46 while((indexOfBang = spec.lastIndexOf('!', indexOfBang)) != -1) { |
48 if ((indexOfBang != (spec.length() - 1)) && |
47 if ((indexOfBang != (spec.length() - 1)) && |
49 (spec.charAt(indexOfBang + 1) == '/')) { |
48 (spec.charAt(indexOfBang + 1) == '/')) { |
50 return indexOfBang + 1; |
49 return indexOfBang + 1; |
53 } |
52 } |
54 } |
53 } |
55 return -1; |
54 return -1; |
56 } |
55 } |
57 |
56 |
|
57 /** |
|
58 * Compare two jar URLs |
|
59 */ |
|
60 @Override |
|
61 protected boolean sameFile(URL u1, URL u2) { |
|
62 if (!u1.getProtocol().equals("jar") || !u2.getProtocol().equals("jar")) |
|
63 return false; |
|
64 |
|
65 String file1 = u1.getFile(); |
|
66 String file2 = u2.getFile(); |
|
67 int sep1 = file1.indexOf(separator); |
|
68 int sep2 = file2.indexOf(separator); |
|
69 |
|
70 if (sep1 == -1 || sep2 == -1) { |
|
71 return super.sameFile(u1, u2); |
|
72 } |
|
73 |
|
74 String entry1 = file1.substring(sep1 + 2); |
|
75 String entry2 = file2.substring(sep2 + 2); |
|
76 |
|
77 if (!entry1.equals(entry2)) |
|
78 return false; |
|
79 |
|
80 URL enclosedURL1 = null, enclosedURL2 = null; |
|
81 try { |
|
82 enclosedURL1 = new URL(file1.substring(0, sep1)); |
|
83 enclosedURL2 = new URL(file2.substring(0, sep2)); |
|
84 } catch (MalformedURLException unused) { |
|
85 return super.sameFile(u1, u2); |
|
86 } |
|
87 |
|
88 if (!super.sameFile(enclosedURL1, enclosedURL2)) { |
|
89 return false; |
|
90 } |
|
91 |
|
92 return true; |
|
93 } |
|
94 |
|
95 @Override |
|
96 protected int hashCode(URL u) { |
|
97 int h = 0; |
|
98 |
|
99 String protocol = u.getProtocol(); |
|
100 if (protocol != null) |
|
101 h += protocol.hashCode(); |
|
102 |
|
103 String file = u.getFile(); |
|
104 int sep = file.indexOf(separator); |
|
105 |
|
106 if (sep == -1) |
|
107 return h + file.hashCode(); |
|
108 |
|
109 URL enclosedURL = null; |
|
110 String fileWithoutEntry = file.substring(0, sep); |
|
111 try { |
|
112 enclosedURL = new URL(fileWithoutEntry); |
|
113 h += enclosedURL.hashCode(); |
|
114 } catch (MalformedURLException unused) { |
|
115 h += fileWithoutEntry.hashCode(); |
|
116 } |
|
117 |
|
118 String entry = file.substring(sep + 2); |
|
119 h += entry.hashCode(); |
|
120 |
|
121 return h; |
|
122 } |
|
123 |
|
124 |
|
125 @Override |
58 protected void parseURL(URL url, String spec, |
126 protected void parseURL(URL url, String spec, |
59 int start, int limit) { |
127 int start, int limit) { |
60 String file = null; |
128 String file = null; |
61 String ref = null; |
129 String ref = null; |
62 // first figure out if there is an anchor |
130 // first figure out if there is an anchor |