Support for data:
URLs for JVM languages.
By default, the Java class java.net.URL
does not support data:
URLs (specified in RFC 2397).
As a result, code snippets like this throw a MalformedURLException
(unknown protocol) on the first line:
java.net.URL url = new java.net.URL("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");
java.awt.image.BufferedImage image = javax.imageio.ImageIO.read(URL);
This library hooks into the Java ServiceLoader architecture for URL stream handlers and provides support for data:
URLs.
To use it, simply add it to the classpath (it has no additional, transitive dependencies).
For e.g., Maven, this means adding this dependency:
<dependency>
<groupId>net.fs.opk</groupId>
<artifactId>data-url</artifactId>
<version>1.0</version>
</dependency>
With this dependency on the classpath, the code snippet above succeeds, and reads an image:
(note that an actual image file is used in this readme because GitHub does not allow data:
URLs)