You can use this code to escape urls:
Code:
private static char[] ESCAPED = {
' ', '<', '>', '#', '%', '{', '}', '|', '\\', '^',
'~', '[', ']', '`', ';', '?', ':', '@', '=', '&', '$'
};
public static String escapeChar(
char c) {
for (int j = 0; j <
ESCAPED.length; j++) {
if (c == ESCAPED[j]) {
return '%' + Integer.toHexString(c);
}
}
return String.valueOf(c);
}
public static String escapeURL(
String s) {
if (s == null || s.equals("")) {
return "";
}
StringBuffer escaped = new StringBuffer();
for (int i = 0; i <
s.length(); i++) {
char c = s.charAt(i);
escaped.append(escapeChar(c));
}
return escaped.toString();
}