Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 1.58 KB

README.md

File metadata and controls

38 lines (25 loc) · 1.58 KB

Build Status license Maven Central

data-url

Support for data: URLs for JVM languages.

Rationale

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);

Usage

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: red dot

(note that an actual image file is used in this readme because GitHub does not allow data: URLs)