LdapURLUtils { public static String encode(String str) { char[] legalChars = { ':' , '/' , '?' , '#' , '[' , ']' , '@', '!' , '$' , '&' , '\'' , '(' , ')', '*' , '+' , ',' , ';' , '=', '-' , '.' , '_' , '~', }; StringBuilder url = new StringBuilder(); char curChar; boolean encoded = false; for (int i = 0; i < str.length(); i++) { curChar = str.charAt(i); if (Character.isLetter(curChar) || Character.isDigit(curChar) || contains(legalChars, curChar) || charIsEncoded(str, i)) { url.append(curChar); } else { url.append(getEncodedChar(curChar)); encoded = true; } } if (encoded) { LOG.warn("The obtained ldap url [{}] contains illegal characters. Use encoded address instead : [{}]", str, url); } return url.toString(); } private  LdapURLUtils(); static String encode(String str);  }
@Test public void test() { assertEquals("ldap: assertEquals("ldap: assertEquals("ldap: assertEquals("ldap: assertEquals("ldap: assertEquals("ldap: assertEquals("ldap: assertEquals("ldap: LdapURLUtils.encode("ldap: assertEquals("ldap: LdapURLUtils.encode("ldap: }