That does not produce a URL encoded string.
Base64.getUrlEncoder() returns a URL-safe base64 encoder - that is, it is a Base64 encoder that only uses characters that are "url-safe". Specifically it uses _ and - for the 2 non-alphnumeric characters and doesn't include newlines.
That is not a URL encoder.
Unfortunately, I don't believe painless includes support for URL encoding.