Created
August 29, 2011 15:00
-
-
Save gjoseph/1178561 to your computer and use it in GitHub Desktop.
And another irked gist, which turned out to be unneeded after all.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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