1 |
|
package org.codehaus.mojo.exec; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.UnsupportedEncodingException; |
24 |
|
import java.net.MalformedURLException; |
25 |
|
import java.net.URL; |
26 |
|
import java.util.BitSet; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 9 |
Complexity Density: 0.53 |
|
31 |
|
public final class UrlUtils { |
32 |
|
private static final BitSet UNRESERVED = new BitSet(Byte.MAX_VALUE - Byte.MIN_VALUE + 1); |
33 |
|
|
34 |
|
private static final int RADIX = 16; |
35 |
|
|
36 |
|
private static final int MASK = 0xf; |
37 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
38 |
0
|
private UrlUtils() {... |
39 |
|
} |
40 |
|
|
41 |
|
private static final String ENCODING = "UTF-8"; |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
43 |
0
|
static {... |
44 |
0
|
try { |
45 |
0
|
byte[] bytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'():/" |
46 |
|
.getBytes(ENCODING); |
47 |
0
|
for (int i = 0; i < bytes.length; i++) { |
48 |
0
|
UNRESERVED.set(bytes[i]); |
49 |
|
} |
50 |
|
} catch (UnsupportedEncodingException e) { |
51 |
|
|
52 |
|
} |
53 |
|
} |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
55 |
0
|
public static URL getURL(File file) throws MalformedURLException {... |
56 |
0
|
URL url = new URL(file.toURI().toASCIIString()); |
57 |
|
|
58 |
|
|
59 |
0
|
try { |
60 |
0
|
byte[] bytes = url.toString().getBytes(ENCODING); |
61 |
0
|
StringBuffer buf = new StringBuffer(bytes.length); |
62 |
0
|
for (int i = 0; i < bytes.length; i++) { |
63 |
0
|
byte b = bytes[i]; |
64 |
0
|
if (b > 0 && UNRESERVED.get(b)) { |
65 |
0
|
buf.append((char) b); |
66 |
|
} else { |
67 |
0
|
buf.append('%'); |
68 |
0
|
buf.append(Character.forDigit(b >>> 4 & MASK, RADIX)); |
69 |
0
|
buf.append(Character.forDigit(b & MASK, RADIX)); |
70 |
|
} |
71 |
|
} |
72 |
0
|
return new URL(buf.toString()); |
73 |
|
} catch (UnsupportedEncodingException e) { |
74 |
|
|
75 |
0
|
throw new RuntimeException(e); |
76 |
|
} |
77 |
|
} |
78 |
|
} |