public static String encode(String str) {
		if (str.matches("[a-zA-Z0-9 ]*"))
			return str;
		
		StringBuilder builder = new StringBuilder(str.length() * 3);
		for (int i = 0; i < str.length(); ++i) {
			char c = str.charAt(i);
			if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c &&
					c <= '9' || c == ' ')
				builder.append(c);
			else
				builder.append('%').append(Character.forDigit(c >> 4 & 15, 16))
						.append(Character.forDigit(c & 15, 16));
		}
		return builder.toString();
	}