com.uwyn.urlencoder

What is it

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.

Why use it

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.

Getting Started

import com.uwyn.urlencoder.UrlEncoder;

void main() {
    var string = "Hello world";
    var encoded = UrlEncoder.encode(string);
    System.out.println(encoded); // Hello%20world
    var decoded = UrlEncoder.decode(encoded);
    System.out.println(decoded); // Hello world
}

<- Index