fileStart = UrlUtils.findFirstOf(spec, "/?#", authorityStart, end); authority = spec.substring(authorityStart, fileStart); int userInfoEnd = UrlUtils.findFirstOf(spec, "@", authorityStart, fileStart); int hostStart; if (userInfoEnd != fileStart) { int ipv6End = UrlUtils.findFirstOf(spec, "]", hostStart, fileStart); if (ipv6End != fileStart) { if (UrlUtils.findFirstOf(spec, ":", hostStart, ipv6End) == ipv6End) { throw new IllegalArgumentException("Expected an IPv6 address: " + spec.substring(hostStart, ipv6End + 1)); int hostEnd = UrlUtils.findFirstOf(spec, ":", colonSearchFrom, fileStart); host = spec.substring(hostStart, hostEnd); int portStart = hostEnd + 1; break; case '?': nextPos = UrlUtils.findFirstOf(spec, "#", pos, end); query = spec.substring(pos + 1, nextPos); ref = null; break; default: nextPos = UrlUtils.findFirstOf(spec, "?#", pos, end); path = relativePath(path, spec.substring(pos, nextPos)); query = null; path = UrlUtils.authoritySafePath(authority, path);
/** * Returns a new path by resolving {@code path} relative to {@code base}. */ private static String relativePath(String base, String path) { if (path.startsWith("/")) { return UrlUtils.canonicalizePath(path, true); } else if (base != null) { String combined = base.substring(0, base.lastIndexOf('/') + 1) + path; return UrlUtils.canonicalizePath(combined, true); } else { return path; } }
protocol = UrlUtils.getSchemePrefix(spec); int schemeSpecificPartStart = protocol != null ? (protocol.length() + 1) : 0;
private String validateScheme(String uri, int end) throws URISyntaxException { if (end == 0) { throw new URISyntaxException(uri, "Scheme expected", 0); } for (int i = 0; i < end; i++) { if (!UrlUtils.isValidSchemeChar(i, uri.charAt(i))) { throw new URISyntaxException(uri, "Illegal character in scheme", 0); } } return uri.substring(0, end); }
this.port = port; file = UrlUtils.authoritySafePath(host, file);
int fragmentStart = UrlUtils.findFirstOf(uri, "#", 0, uri.length()); if (fragmentStart < uri.length()) { fragment = ALL_LEGAL_ENCODER.validate(uri, fragmentStart + 1, uri.length(), "fragment"); int colon = UrlUtils.findFirstOf(uri, ":", 0, fragmentStart); if (colon < UrlUtils.findFirstOf(uri, "/?#", 0, fragmentStart)) { absolute = true; scheme = validateScheme(uri, colon); if (uri.regionMatches(start, "//", 0, 2)) { int authorityStart = start + 2; fileStart = UrlUtils.findFirstOf(uri, "/?", authorityStart, fragmentStart); if (authorityStart == uri.length()) { throw new URISyntaxException(uri, "Authority expected", uri.length()); int queryStart = UrlUtils.findFirstOf(uri, "?", fileStart, fragmentStart); path = PATH_ENCODER.validate(uri, fileStart, queryStart, "path");
/** * Returns the scheme prefix like "http" from the URL spec, or null if the * spec doesn't start with a scheme. Scheme prefixes match this pattern: * {@code alpha ( alpha | digit | '+' | '-' | '.' )* ':'} */ public static String getSchemePrefix(String spec) { int colon = spec.indexOf(':'); if (colon < 1) { return null; } for (int i = 0; i < colon; i++) { char c = spec.charAt(i); if (!isValidSchemeChar(i, c)) { return null; } } return spec.substring(0, colon).toLowerCase(Locale.US); }
resolvedPath = path.substring(0, endIndex) + relative.path; result.path = UrlUtils.authoritySafePath(result.authority, normalize(resolvedPath, true)); result.setSchemeSpecificPart(); return result;
int fragmentStart = UrlUtils.findFirstOf(uri, "#", 0, uri.length()); if (fragmentStart < uri.length()) { fragment = ALL_LEGAL_ENCODER.validate(uri, fragmentStart + 1, uri.length(), "fragment"); int colon = UrlUtils.findFirstOf(uri, ":", 0, fragmentStart); if (colon < UrlUtils.findFirstOf(uri, "/?#", 0, fragmentStart)) { absolute = true; scheme = validateScheme(uri, colon); if (uri.regionMatches(start, "//", 0, 2)) { int authorityStart = start + 2; fileStart = UrlUtils.findFirstOf(uri, "/?", authorityStart, fragmentStart); if (authorityStart == uri.length()) { throw new URISyntaxException(uri, "Authority expected", uri.length()); int queryStart = UrlUtils.findFirstOf(uri, "?", fileStart, fragmentStart); path = PATH_ENCODER.validate(uri, fileStart, queryStart, "path");
fileStart = UrlUtils.findFirstOf(spec, "/?#", authorityStart, end); authority = spec.substring(authorityStart, fileStart); int userInfoEnd = UrlUtils.findFirstOf(spec, "@", authorityStart, fileStart); int hostStart; if (userInfoEnd != fileStart) { int ipv6End = UrlUtils.findFirstOf(spec, "]", hostStart, fileStart); if (ipv6End != fileStart) { if (UrlUtils.findFirstOf(spec, ":", hostStart, ipv6End) == ipv6End) { throw new IllegalArgumentException("Expected an IPv6 address: " + spec.substring(hostStart, ipv6End + 1)); int hostEnd = UrlUtils.findFirstOf(spec, ":", colonSearchFrom, fileStart); host = spec.substring(hostStart, hostEnd); int portStart = hostEnd + 1; break; case '?': nextPos = UrlUtils.findFirstOf(spec, "#", pos, end); query = spec.substring(pos + 1, nextPos); ref = null; break; default: nextPos = UrlUtils.findFirstOf(spec, "?#", pos, end); path = relativePath(path, spec.substring(pos, nextPos)); query = null; path = UrlUtils.authoritySafePath(authority, path);
/** * Returns the normalized path. */ private String normalize(String path, boolean discardRelativePrefix) { path = UrlUtils.canonicalizePath(path, discardRelativePrefix); /* * If the path contains a colon before the first colon, prepend * "./" to differentiate the path from a scheme prefix. */ int colon = path.indexOf(':'); if (colon != -1) { int slash = path.indexOf('/'); if (slash == -1 || colon < slash) { path = "./" + path; } } return path; }
private String validateScheme(String uri, int end) throws URISyntaxException { if (end == 0) { throw new URISyntaxException(uri, "Scheme expected", 0); } for (int i = 0; i < end; i++) { if (!UrlUtils.isValidSchemeChar(i, uri.charAt(i))) { throw new URISyntaxException(uri, "Illegal character in scheme", 0); } } return uri.substring(0, end); }
this.port = port; file = UrlUtils.authoritySafePath(host, file);
protocol = UrlUtils.getSchemePrefix(spec); int schemeSpecificPartStart = protocol != null ? (protocol.length() + 1) : 0;
int fragmentStart = UrlUtils.findFirstOf(uri, "#", 0, uri.length()); if (fragmentStart < uri.length()) { fragment = ALL_LEGAL_ENCODER.validate(uri, fragmentStart + 1, uri.length(), "fragment"); int colon = UrlUtils.findFirstOf(uri, ":", 0, fragmentStart); if (colon < UrlUtils.findFirstOf(uri, "/?#", 0, fragmentStart)) { absolute = true; scheme = validateScheme(uri, colon); if (uri.regionMatches(start, "//", 0, 2)) { int authorityStart = start + 2; fileStart = UrlUtils.findFirstOf(uri, "/?", authorityStart, fragmentStart); if (authorityStart == uri.length()) { throw new URISyntaxException(uri, "Authority expected", uri.length()); int queryStart = UrlUtils.findFirstOf(uri, "?", fileStart, fragmentStart); path = PATH_ENCODER.validate(uri, fileStart, queryStart, "path");
fileStart = UrlUtils.findFirstOf(spec, "/?#", authorityStart, end); authority = spec.substring(authorityStart, fileStart); int userInfoEnd = UrlUtils.findFirstOf(spec, "@", authorityStart, fileStart); int hostStart; if (userInfoEnd != fileStart) { int ipv6End = UrlUtils.findFirstOf(spec, "]", hostStart, fileStart); if (ipv6End != fileStart) { if (UrlUtils.findFirstOf(spec, ":", hostStart, ipv6End) == ipv6End) { throw new IllegalArgumentException("Expected an IPv6 address: " + spec.substring(hostStart, ipv6End + 1)); int hostEnd = UrlUtils.findFirstOf(spec, ":", colonSearchFrom, fileStart); host = spec.substring(hostStart, hostEnd); int portStart = hostEnd + 1; break; case '?': nextPos = UrlUtils.findFirstOf(spec, "#", pos, end); query = spec.substring(pos + 1, nextPos); ref = null; break; default: nextPos = UrlUtils.findFirstOf(spec, "?#", pos, end); path = relativePath(path, spec.substring(pos, nextPos)); query = null; path = UrlUtils.authoritySafePath(authority, path);
int idx = file.indexOf('!'); String tmpFile = file.substring(idx + 1, file.lastIndexOf('/') + 1) + spec; tmpFile = UrlUtils.canonicalizePath(tmpFile, true); file = file.substring(0, idx + 1) + tmpFile;
private String validateScheme(String uri, int end) throws URISyntaxException { if (end == 0) { throw new URISyntaxException(uri, "Scheme expected", 0); } for (int i = 0; i < end; i++) { if (!UrlUtils.isValidSchemeChar(i, uri.charAt(i))) { throw new URISyntaxException(uri, "Illegal character in scheme", 0); } } return uri.substring(0, end); }
this.port = port; file = UrlUtils.authoritySafePath(host, file);
protocol = UrlUtils.getSchemePrefix(spec); int schemeSpecificPartStart = protocol != null ? (protocol.length() + 1) : 0;