RFR: 8293971: Loading new Media from resources can sometimes fail when loading from FXML

Andy Goryachev angorya at openjdk.org
Mon Sep 26 15:26:16 UTC 2022


On Sat, 24 Sep 2022 03:07:00 GMT, Alexander Matveev <almatvee at openjdk.org> wrote:

> There was two problems:
>  - uri.getPath() was returning null for jar URI, since it is not a standard URI and thus we did not detect file type based on extension.
>  - Our signature detection for MP3 had a bug and did not detect MP3 correctly. See comments in code.
>  
> Fixed by adding function to extract file name from jar URI and also signature detection was fixed for MP3.

modules/javafx.media/src/main/java/com/sun/media/jfxmedia/locator/Locator.java line 425:

> 423:                             stream.close();
> 424:                             isConnected = true;
> 425:                             contentType = MediaUtils.filenameToContentType(uri); // We need to provide at least something

would it be possible to explain what ie being done instead?  i.e. "try to determine the content type based on extension" or something like that?

modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/MediaUtils.java line 154:

> 152:         } else if ((buf[0] & 0xff) == 0xff && (buf[1] & 0xe0) == 0xe0 && // sync
> 153:                 (buf[1] & 0x18) != 0x08 && // not reserved version
> 154:                 (buf[1] & 0x06) != 0x00) { // not reserved layer

thank you for providing a descriptive comment!

I wonder if, in the future, when the list of supported formats grows, we ought to invent some kind of Bit(input)Stream class that would make operating on bit fields easier?

modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/MediaUtils.java line 187:

> 185:      * Returns the content type given the file name.
> 186:      *
> 187:      * @param uri

should the comment be changed since the argument is uri and not a file name?

modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/MediaUtils.java line 241:

> 239: 
> 240:         String scheme = uri.getScheme().toLowerCase();
> 241:         if (scheme.equals("jar")) {

is it possible for the 'scheme' to be null?

(may be "jar".equals(scheme) would work better here?)

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

PR: https://git.openjdk.org/jfx/pull/902


More information about the openjfx-dev mailing list