When adding this library in your classpath, you will be able to handle "data URLs" (RFC-2397) in your application.
You need Java ≥ 11 to use this library.
When you want to get the content of a "data URL":
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.<init>(URL.java:779)
at java.base/java.net.URL.<init>(URL.java:654)
at java.base/java.net.URL.<init>(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!
To add this library to your Maven project:
<dependency>
<groupId>io.github.jycr</groupId>
<artifactId>java-data-url-handler</artifactId>
<version>${java-data-url-handler.version}</version>
</dependency>