Skip to content

Instantly share code, notes, and snippets.

@gjoseph
Created August 29, 2011 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjoseph/1178561 to your computer and use it in GitHub Desktop.
Save gjoseph/1178561 to your computer and use it in GitHub Desktop.
And another irked gist, which turned out to be unneeded after all.
/**
* So java.net.URLEncoder#encode(java.lang.String) is deprecated, because it uses the OS' default encoding,
* java.net.URLEncoder#encode(java.lang.String, java.lang.String) takes a second parameter for said encoding,
* while mentioning that "The World Wide Web Consortium Recommendation states that UTF-8 should be used.
* Not doing so may introduce incompatibilites.". (typo not mine).
* Still, we have to choose, read doc, and specify the ourselves, and deal with the uncanny possibility that
* UTF-8 might not be available on a system where we do have a 1.6 JVM.
* Right.
*/
public static String encode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Dude, running Java 1.6 but not supporting UTF-8 ? What is wrong with you ?", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment