Java equivalent of Ruby's URI.escape?
Today I had to escape URL (http://rfc3986.openrfc.org/ - for instance, replace 'space' character with %20) and surprisingly I couldn't find any API in Java which would take unescaped URL as 1 parameter and return escaped URL.
I am aware of URI class which is capable of performing escaping operation, however it's required to use multiargument contructor (http://download.oracle.com/javase/1.4.2/docs/api/java/net/URI.html#URI(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, java.lang.String)), using single-argument contructor simply doesn't perform escaping bu开发者_运维百科t throws an exception.
Luckily, I was already emedding JRuby library so I was able to use URI.escape method http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI/Escape.html however I'm really surprised there is no easy way to achieve same effect in Java.
Am I missing some API?
精彩评论