Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/opwvhk/data-url
Java support for RFC2397 data: URLs by java.net.URL
https://github.com/opwvhk/data-url
Last synced: 9 days ago
JSON representation
Java support for RFC2397 data: URLs by java.net.URL
- Host: GitHub
- URL: https://github.com/opwvhk/data-url
- Owner: opwvhk
- License: apache-2.0
- Created: 2020-06-04T11:50:25.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-22T20:18:50.000Z (4 months ago)
- Last Synced: 2024-08-22T22:26:40.414Z (4 months ago)
- Language: Java
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
![Build Status](https://github.com/opwvhk/data-url/workflows/Maven%20Build/badge.svg)
[![license](doc/license-APACHE-2.0-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.sf.opk/data-url/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.sf.opk/data-url)# 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](https://www.ietf.org/rfc/rfc2397.txt)).
As a result, code snippets like this throw a `MalformedURLException` (unknown protocol) on the first line:
``` java
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:
```xml
net.fs.opk
data-url
1.0```
With this dependency on the classpath, the code snippet above succeeds, and reads an image: ![red dot](doc/red-dot-5px.png "red dot")
(note that an actual image file is used in this readme because GitHub does not allow `data:` URLs)