The data-url library adds support for the data protocol as specified in RFC 2397.

There are several ways to create data URLs. Most are described by the URL class.

  1. Make use of a shared URLStreamHandlerFactory set on the URL class. This must return an instance of Handler for the data protocol.
  2. Add package to system property java.protocol.handler.pkgs.
  3. Use this URL constructor, and provide an instance of Handler as the URLStreamHandler. The context argument can remain null.
    • It’s ill-advised to use this constructor, because it does not ensure the data URL is correctly formatted.
  4. Use utility class DataURLs.

Note that class Handler is stateless, and therefore instances can be shared among multiple threads.