Skip to content

Repository files navigation

License MITPublish package to the Maven Central RepositoryVersion on Maven CentralQuality Gate Status

java-data-url-handler

When adding this library in your classpath, you will be able to handle "data URLs" (RFC-2397) in your application.

Prerequisites

You need Java ≥ 11 to use this library.

Usage

When you want to get the content of a "data URL":

importjava.io.IOException;
importjava.io.InputStream;
importjava.net.URI;
importjava.nio.charset.StandardCharsets;
publicclassTest {
publicstaticvoidmain(String[] args) throwsIOException {
URLurl = URI.create("data:text/plain,Hello%2C%20World!").toURL();
try(InputStreamin = url.openStream()) {
System.out.println(newString(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!

Add dependency to your project

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>

Latest available version: Version on Maven Central

About

"data" URL scheme (RFC 2397) Java handler

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages