https://github.com/jycr/java-data-url-handler
"data" URL scheme (RFC 2397) Java handler
https://github.com/jycr/java-data-url-handler
java protocol-handler rfc-2397
Last synced: 2 months ago
JSON representation
"data" URL scheme (RFC 2397) Java handler
- Host: GitHub
- URL: https://github.com/jycr/java-data-url-handler
- Owner: jycr
- License: mit
- Created: 2024-08-20T01:49:08.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-08-28T01:52:42.000Z (9 months ago)
- Last Synced: 2025-02-01T22:13:40.298Z (4 months ago)
- Topics: java, protocol-handler, rfc-2397
- Language: Java
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/license/mit)
[](https://github.com/jycr/java-data-url-handler/actions/workflows/publish_to_maven_central.yml)
[](https://search.maven.org/artifact/io.github.jycr/java-data-url-handler)
[](https://sonarcloud.io/summary/new_code?id=jycr_java-data-url-handler)# java-data-url-handler
When adding this library in your classpath, you will be able to handle "data URLs" ([RFC-2397](https://datatracker.ietf.org/doc/html/rfc2397)) in your application.
## Prerequisites
You need Java ≥ 11 to use this library.
## Usage
When you want to get the content of a "data URL":
```java
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;public class Test {
public static void main(String[] args) throws IOException {
URL url = URI.create("data:text/plain,Hello%2C%20World!").toURL();
try(InputStream in = url.openStream()) {
System.out.println(new String(in.readAllBytes(), StandardCharsets.UTF_8));
}
}
}
```Without this library, you will get an error like this:
```
Exception in thread "main" java.net.MalformedURLException: unknown protocol: data
at java.base/java.net.URL.(URL.java:779)
at java.base/java.net.URL.(URL.java:654)
at java.base/java.net.URL.(URL.java:590)
```With this library in your classpath, you can handle the data URL and get the content of the data URL.
The output of the code above will be:
```
Hello, World!
```## Add dependency to your project
To add this library to your Maven project:
```xml
io.github.jycr
java-data-url-handler
${java-data-url-handler.version}```
Latest available version: 