/** * Encodes the given source URI into an encoded String. All various URI components are * encoded according to their respective valid character sets. * <p>This method does <b>not</b> attempt to encode "=" and "{@literal &}" * characters in query parameter names and query parameter values because they cannot * be parsed in a reliable way. */ public static String encodeUri(final String uri, final String encoding) { Matcher m = URI_PATTERN.matcher(uri); if (m.matches()) { String scheme = m.group(2); String authority = m.group(3); String userinfo = m.group(5); String host = m.group(6); String port = m.group(8); String path = m.group(9); String query = m.group(11); String fragment = m.group(13); return encodeUriComponents(scheme, authority, userinfo, host, port, path, query, fragment, encoding); } throw new IllegalArgumentException("Invalid URI: " + uri); }
/** * Encodes the given HTTP URI into an encoded String. All various URI components are * encoded according to their respective valid character sets. * <p>This method does <b>not</b> support fragments ({@code #}), * as these are not supposed to be sent to the server, but retained by the client. * <p>This method does <b>not</b> attempt to encode "=" and "{@literal &}" * characters in query parameter names and query parameter values because they cannot * be parsed in a reliable way. */ public static String encodeHttpUrl(final String httpUrl, final String encoding) { Matcher m = HTTP_URL_PATTERN.matcher(httpUrl); if (m.matches()) { String scheme = m.group(1); String authority = m.group(2); String userinfo = m.group(4); String host = m.group(5); String portString = m.group(7); String path = m.group(8); String query = m.group(10); return encodeUriComponents(scheme, authority, userinfo, host, portString, path, query, null, encoding); } throw new IllegalArgumentException("Invalid HTTP URL: " + httpUrl); }
/** * Encodes the given source URI into an encoded String. All various URI components are * encoded according to their respective valid character sets. * <p>This method does <b>not</b> attempt to encode "=" and "{@literal &}" * characters in query parameter names and query parameter values because they cannot * be parsed in a reliable way. */ public static String encodeUri(final String uri, final String encoding) { Matcher m = URI_PATTERN.matcher(uri); if (m.matches()) { String scheme = m.group(2); String authority = m.group(3); String userinfo = m.group(5); String host = m.group(6); String port = m.group(8); String path = m.group(9); String query = m.group(11); String fragment = m.group(13); return encodeUriComponents(scheme, authority, userinfo, host, port, path, query, fragment, encoding); } throw new IllegalArgumentException("Invalid URI: " + uri); }
/** * Encodes the given HTTP URI into an encoded String. All various URI components are * encoded according to their respective valid character sets. * <p>This method does <b>not</b> support fragments ({@code #}), * as these are not supposed to be sent to the server, but retained by the client. * <p>This method does <b>not</b> attempt to encode "=" and "{@literal &}" * characters in query parameter names and query parameter values because they cannot * be parsed in a reliable way. */ public static String encodeHttpUrl(final String httpUrl, final String encoding) { Matcher m = HTTP_URL_PATTERN.matcher(httpUrl); if (m.matches()) { String scheme = m.group(1); String authority = m.group(2); String userinfo = m.group(4); String host = m.group(5); String portString = m.group(7); String path = m.group(8); String query = m.group(10); return encodeUriComponents(scheme, authority, userinfo, host, portString, path, query, null, encoding); } throw new IllegalArgumentException("Invalid HTTP URL: " + httpUrl); }