Skip to content

Commit

Permalink
8293742: Better Banking of Sounds
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken, mbalao
Backport-of: f1de79f38fcff10ccaf232f79df0a94e84751ff7
  • Loading branch information
Aleksei Voitylov authored and RealCLanger committed Dec 28, 2022
1 parent 5fd24c4 commit b46279b
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -48,6 +48,13 @@
*/
public final class JARSoundbankReader extends SoundbankReader {

/*
* Name of the system property that enables the Jar soundbank loading
* true if jar sound bank is allowed to be loaded
* default is false
*/
private final static String JAR_SOUNDBANK_ENABLED = "jdk.sound.jarsoundbank";

private static boolean isZIP(URL url) {
boolean ok = false;
try {
Expand All @@ -73,8 +80,10 @@ private static boolean isZIP(URL url) {
@SuppressWarnings("deprecation")
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
if (!isZIP(url))
Objects.requireNonNull(url);
if (!Boolean.getBoolean(JAR_SOUNDBANK_ENABLED) || !isZIP(url))
return null;

ArrayList<Soundbank> soundbanks = new ArrayList<>();
URLClassLoader ucl = URLClassLoader.newInstance(new URL[]{url});
InputStream stream = ucl.getResourceAsStream(
Expand Down Expand Up @@ -124,6 +133,7 @@ public Soundbank getSoundbank(InputStream stream)
@Override
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
Objects.requireNonNull(file);
return getSoundbank(file.toURI().toURL());
}
}

0 comments on commit b46279b

Please sign in to comment.