MCPcopy Create free account
hub / github.com/apache/tomcat / UriUtil

Class UriUtil

java/org/apache/tomcat/util/buf/UriUtil.java:30–309  ·  view source on GitHub ↗

Utility class for working with URIs and URLs.

Source from the content-addressed store, hash-verified

28 * Utility class for working with URIs and URLs.
29 */
30public final class UriUtil {
31
32 private static final char[] HEX =
33 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
34
35 private static final Pattern PATTERN_EXCLAMATION_MARK = Pattern.compile("!/");
36 private static final Pattern PATTERN_ASTERISK = Pattern.compile("\\*/");
37 private static final Pattern PATTERN_CUSTOM;
38 private static final String REPLACE_CUSTOM;
39
40 private static final String WAR_SEPARATOR;
41
42 static {
43 String custom = System.getProperty("org.apache.tomcat.util.buf.UriUtil.WAR_SEPARATOR");
44 if (custom == null) {
45 WAR_SEPARATOR = "*/";
46 PATTERN_CUSTOM = null;
47 REPLACE_CUSTOM = null;
48 } else {
49 WAR_SEPARATOR = custom + "/";
50 PATTERN_CUSTOM = Pattern.compile(Pattern.quote(WAR_SEPARATOR));
51 StringBuilder sb = new StringBuilder(custom.length() * 3);
52 // Deliberately use the platform's default encoding
53 byte[] ba = custom.getBytes();
54 for (byte toEncode : ba) {
55 // Converting each byte in the buffer
56 sb.append('%');
57 int low = toEncode & 0x0f;
58 int high = (toEncode & 0xf0) >> 4;
59 sb.append(HEX[high]);
60 sb.append(HEX[low]);
61 }
62 REPLACE_CUSTOM = sb.toString();
63 }
64 }
65
66
67 private UriUtil() {
68 // Utility class. Hide default constructor
69 }
70
71
72 /**
73 * Determine if the character is allowed in the scheme of a URI. See RFC 2396, Section 3.1
74 *
75 * @param c The character to test
76 *
77 * @return {@code true} if the character is allowed, otherwise {@code
78 * false}
79 */
80 private static boolean isSchemeChar(char c) {
81 return Character.isLetterOrDigit(c) || c == '+' || c == '-' || c == '.';
82 }
83
84
85 /**
86 * Determine if a URI string has a <code>scheme</code> component.
87 *

Callers

nothing calls this directly

Calls 7

lengthMethod · 0.80
getPropertyMethod · 0.65
toStringMethod · 0.65
compileMethod · 0.45
quoteMethod · 0.45
getBytesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected