@Test public void testEncodeEmptyString() { Assert.assertEquals("urlEncode(\"\") returned something unexpected", "", SdkHttpUtils.urlEncode("", false)); }
public static String urlEncode(final String value, final boolean path) { if (value == null) { return ""; } try { String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); StringBuffer buffer = new StringBuffer(encoded.length()); while (matcher.find()) { String replacement = matcher.group(0); if ("+".equals(replacement)) { replacement = "%20"; } else if ("*".equals(replacement)) { replacement = "%2A"; } else if ("%7E".equals(replacement)) { replacement = "~"; } else if (path && "%2F".equals(replacement)) { replacement = "/"; } matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }
SdkHttpUtils { public static String urlEncode(final String value, final boolean path) { if (value == null) { return ""; } try { String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); StringBuffer buffer = new StringBuffer(encoded.length()); while (matcher.find()) { String replacement = matcher.group(0); if ("+".equals(replacement)) { replacement = "%20"; } else if ("*".equals(replacement)) { replacement = "%2A"; } else if ("%7E".equals(replacement)) { replacement = "~"; } else if (path && "%2F".equals(replacement)) { replacement = "/"; } matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } } }
SdkHttpUtils { public static String urlEncode(final String value, final boolean path) { if (value == null) { return ""; } try { String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); StringBuffer buffer = new StringBuffer(encoded.length()); while (matcher.find()) { String replacement = matcher.group(0); if ("+".equals(replacement)) { replacement = "%20"; } else if ("*".equals(replacement)) { replacement = "%2A"; } else if ("%7E".equals(replacement)) { replacement = "~"; } else if (path && "%2F".equals(replacement)) { replacement = "/"; } matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }  }
SdkHttpUtils { public static String urlEncode(final String value, final boolean path) { if (value == null) { return ""; } try { String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); StringBuffer buffer = new StringBuffer(encoded.length()); while (matcher.find()) { String replacement = matcher.group(0); if ("+".equals(replacement)) { replacement = "%20"; } else if ("*".equals(replacement)) { replacement = "%2A"; } else if ("%7E".equals(replacement)) { replacement = "~"; } else if (path && "%2F".equals(replacement)) { replacement = "/"; } matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }  static String urlEncode(final String value, final boolean path); static String urlDecode(final String value); static boolean isUsingNonDefaultPort(URI uri); static boolean usePayloadForQueryParameters(SignableRequest<?> request); static String encodeParameters(SignableRequest<?> request); static String appendUri(String baseUri, String path); static String appendUri(final String baseUri, String path, final boolean escapeDoubleSlash); }
SdkHttpUtils { public static String urlEncode(final String value, final boolean path) { if (value == null) { return ""; } try { String encoded = URLEncoder.encode(value, DEFAULT_ENCODING); Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded); StringBuffer buffer = new StringBuffer(encoded.length()); while (matcher.find()) { String replacement = matcher.group(0); if ("+".equals(replacement)) { replacement = "%20"; } else if ("*".equals(replacement)) { replacement = "%2A"; } else if ("%7E".equals(replacement)) { replacement = "~"; } else if (path && "%2F".equals(replacement)) { replacement = "/"; } matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }  static String urlEncode(final String value, final boolean path); static String urlDecode(final String value); static boolean isUsingNonDefaultPort(URI uri); static boolean usePayloadForQueryParameters(SignableRequest<?> request); static String encodeParameters(SignableRequest<?> request); static String appendUri(String baseUri, String path); static String appendUri(final String baseUri, String path, final boolean escapeDoubleSlash);  }