https://github.com/robtimus/data-url
Support for data URLs as specified in RFC 2397 (https://www.ietf.org/rfc/rfc2397.txt)
https://github.com/robtimus/data-url
data-uri data-url java rfc-2397
Last synced: 5 months ago
JSON representation
Support for data URLs as specified in RFC 2397 (https://www.ietf.org/rfc/rfc2397.txt)
- Host: GitHub
- URL: https://github.com/robtimus/data-url
- Owner: robtimus
- License: apache-2.0
- Created: 2017-12-23T12:58:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-07-12T12:49:30.000Z (6 months ago)
- Last Synced: 2025-07-13T15:50:44.136Z (6 months ago)
- Topics: data-uri, data-url, java, rfc-2397
- Language: Java
- Homepage: https://robtimus.github.io/data-url/
- Size: 624 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# data-url
[](https://search.maven.org/artifact/com.github.robtimus/data-url)
[](https://github.com/robtimus/data-url/actions/workflows/build.yml)
[](https://sonarcloud.io/summary/overall?id=com.github.robtimus%3Adata-url)
[](https://sonarcloud.io/summary/overall?id=com.github.robtimus%3Adata-url)
[](https://snyk.io/test/github/robtimus/data-url)
The `data-url` library adds support for the `data` protocol as specified in [RFC 2397](https://www.ietf.org/rfc/rfc2397.txt).
There are several ways to create data URLs. Most are described by the [URL](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#URL-java.lang.String-java.lang.String-int-java.lang.String-) class.
1. Make use of a shared [URLStreamHandlerFactory](https://docs.oracle.com/javase/8/docs/api/java/net/URLStreamHandlerFactory.html) set on the [URL](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#setURLStreamHandlerFactory-java.net.URLStreamHandlerFactory-) class. This must return an instance of [Handler](https://robtimus.github.io/data-url/apidocs/com/github/robtimus/net/protocol/data/Handler.html) for the `data` protocol.
2. Add package `com.github.robtimus.net.protocol` to system property `java.protocol.handler.pkgs`.
3. Use [this](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#URL-java.net.URL-java.lang.String-java.net.URLStreamHandler-) URL constructor, and provide an instance of [Handler](https://robtimus.github.io/data-url/apidocs/com/github/robtimus/net/protocol/data/Handler.html) as the [URLStreamHandler](https://docs.oracle.com/javase/8/docs/api/java/net/URLStreamHandler.html). The `context` argument can remain `null`.
* It's ill-advised to use [this](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html#URL-java.lang.String-java.lang.String-int-java.lang.String-java.net.URLStreamHandler-) constructor, because it does not ensure the data URL is correctly formatted.
4. Use utility class [DataURLs](https://robtimus.github.io/data-url/apidocs/com/github/robtimus/net/protocol/data/DataURLs.html).
Note that class [Handler](https://robtimus.github.io/data-url/apidocs/com/github/robtimus/net/protocol/data/Handler.html) is stateless, and therefore instances can be shared among multiple threads.