com.uwyn/urlencoder
com.uwyn.urlencoder
gbevin/urlencoder
urlencoder
encodes URL components using rules determined by combining the unreserved character set from RFC 3986 with the percent-encode set from application/x-www-form-urlencoded.
The built-in java.net.URLEncoder
encodes strings into the "HTML form encoding."
This is very slightly different from the form of encoding that should be used for URLs. In the specifications for URIs (URLs are a subset of URIs), spaces are encoded as %20
. In application/x-www-form-urlencoded
, spaces are usually encoded as +
, though %20
would also be valid.
Because java.net.URLEncoder
uses +
for spaces, other libraries can fail to decode data properly.
The UrlEncoder
class in this library uses %20
for spaces and is also reportedly more efficient than java.net.URLEncoder
.
import com.uwyn.urlencoder.UrlEncoder;
void main() {
= "Hello world";
var string = UrlEncoder.encode(string);
var encoded System.out.println(encoded); // Hello%20world
= UrlEncoder.decode(encoded);
var decoded System.out.println(decoded); // Hello world
}