RFR: 8267551: Support loading images from inline data-URIs [v17]

Kevin Rushforth kcr at openjdk.java.net
Sat Jun 12 14:22:55 UTC 2021


On Wed, 9 Jun 2021 14:20:41 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:

>> This PR adds support for loading images from [inline data URIs](https://en.wikipedia.org/wiki/Data_URI_scheme), which is also widely supported by web browsers. This enables developers to package small images in CSS files, rather than separately deploying the images alongside the CSS file.
>
> Michael Strauß has updated the pull request incrementally with one additional commit since the last revision:
> 
>   doc

I reviewed and tested the implementation. I left a couple questions inline.

modules/javafx.graphics/src/main/java/com/sun/javafx/iio/ImageStorage.java line 314:

> 312:                     }
> 313: 
> 314:                     theStream = new ByteArrayInputStream(dataUri.getData());

By parsing the Data URI before calling `ImageTools.createInputStream` our internal handling will take precedence over a custom handler that an application might have installed. I'm not sure this is what we want.

modules/javafx.graphics/src/main/java/com/sun/javafx/util/DataURI.java line 185:

> 183:     @Override
> 184:     public String toString() {
> 185:         if (originalData.length() < 30) {

I think this should be `< 32`. As it stands, if length is `30` or `31` the data portion of the string will be 31 characters with either 2 or 3 middle chars replaced by `"..."`. In those cases it would be better to just use the original data.

-------------

PR: https://git.openjdk.java.net/jfx/pull/508


More information about the openjfx-dev mailing list