Skip to content

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

License

Notifications You must be signed in to change notification settings

opwvhk/data-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages