Java Base64 URL Safe Encoding

When it comes to common tooling in Java, Guava is your best friend. If you are still using Apache Commons, stop now. Below is the gradle dependency information for guava as of this writing.

compile ''
Base64 URL Safe Encoding
Here is a simple example of encoding text with Base64 with Guava.

public class UrlSafeEncodingExample {

  public static void main(String[] args) {

    String decodedString = args[0];

    System.out.println("Decoded String: " + decodedString);

    String encodedString = BaseEncoding.base64Url().encode(decodedString.getBytes('UTF-8'));

    System.out.println("Encoded String: " + encodedString);

Check out more about Guava in their git repository.


Post a Comment

Popular posts from this blog

Ruby RSpec: Mocks, Doubles, and Spies with Constructor Injection

AWS Lambda HTML to PDF