opwvhk / data-url

Java support for RFC2397 data: URLs by java.net.URL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

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)

About

Java support for RFC2397 data: URLs by java.net.URL

License:Apache License 2.0


Languages

Language:Java 100.0%