提交 777a1ff2 编写于 作者: S serb

8054372: Cleanup of com.sun.media.sound packages

Reviewed-by: azvegint, prr
上级 54e6ab14
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, 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
......@@ -25,6 +25,8 @@
package com.sun.media.sound;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -176,11 +178,11 @@ public final class JDK13Services {
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String value;
String propertyName = typeClass.getName();
value = JSSecurityManager.getProperty(propertyName);
String name = typeClass.getName();
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) {
value = getProperties().getProperty(propertyName);
value = getProperties().getProperty(name);
}
if ("".equals(value)) {
value = null;
......
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, 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
......@@ -73,33 +73,6 @@ final class JSSecurityManager {
}
}
static String getProperty(final String propertyName) {
String propertyValue;
if (hasSecurityManager()) {
if(Printer.debug) Printer.debug("using JDK 1.2 security to get property");
try{
PrivilegedAction<String> action = new PrivilegedAction<String>() {
public String run() {
try {
return System.getProperty(propertyName);
} catch (Throwable t) {
return null;
}
}
};
propertyValue = AccessController.doPrivileged(action);
} catch( Exception e ) {
if(Printer.debug) Printer.debug("not using JDK 1.2 security to get properties");
propertyValue = System.getProperty(propertyName);
}
} else {
if(Printer.debug) Printer.debug("not using JDK 1.2 security to get properties");
propertyValue = System.getProperty(propertyName);
}
return propertyValue;
}
/** Load properties from a file.
This method tries to load properties from the filename give into
the passed properties object.
......
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2014, 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
......@@ -74,17 +74,6 @@ final class Platform {
// intel is little-endian. sparc is big-endian.
private static boolean bigEndian;
// this is the value of the "java.home" system property. i am looking it up here
// for use when trying to load the soundbank, just so
// that all the privileged code is localized in this file....
private static String javahome;
// this is the value of the "java.class.path" system property
private static String classpath;
static {
if(Printer.trace)Printer.trace(">> Platform.java: static");
......@@ -129,26 +118,6 @@ final class Platform {
return signed8;
}
/**
* Obtain javahome.
* $$kk: 04.16.99: this is *bad*!!
*/
static String getJavahome() {
return javahome;
}
/**
* Obtain classpath.
* $$jb: 04.21.99: this is *bad* too!!
*/
static String getClasspath() {
return classpath;
}
// PRIVATE METHODS
/**
......@@ -157,21 +126,13 @@ final class Platform {
private static void loadLibraries() {
if(Printer.trace)Printer.trace(">>Platform.loadLibraries");
try {
// load the main library
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
System.loadLibrary(libNameMain);
return null;
}
});
// just for the heck of it...
loadedLibs |= LIB_MAIN;
} catch (SecurityException e) {
if(Printer.err)Printer.err("Security exception loading main native library. JavaSound requires access to these resources.");
throw(e);
}
// load the main library
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary(libNameMain);
return null;
});
// just for the heck of it...
loadedLibs |= LIB_MAIN;
// now try to load extra libs. They are defined at compile time in the Makefile
// with the define EXTRA_SOUND_JNI_LIBS
......@@ -181,12 +142,9 @@ final class Platform {
while (st.hasMoreTokens()) {
final String lib = st.nextToken();
try {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
System.loadLibrary(lib);
return null;
}
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary(lib);
return null;
});
if (lib.equals(libNameALSA)) {
......@@ -239,7 +197,5 @@ final class Platform {
// $$fb 2002-03-06: implement check for endianness in native. Facilitates porting !
bigEndian = nIsBigEndian();
signed8 = nIsSigned8(); // Solaris on Sparc: signed, all others unsigned
javahome = JSSecurityManager.getProperty("java.home");
classpath = JSSecurityManager.getProperty("java.class.path");
}
}
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2014, 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
......@@ -28,6 +28,7 @@ package com.sun.media.sound;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
......@@ -732,31 +733,28 @@ public final class SoftSynthesizer implements AudioSynthesizer,
* Save generated soundbank to disk for faster future use.
*/
OutputStream out = AccessController
.doPrivileged(new PrivilegedAction<OutputStream>() {
public OutputStream run() {
try {
File userhome = new File(System
.getProperty("user.home"),
".gervill");
if (!userhome.exists())
userhome.mkdirs();
File emg_soundbank_file = new File(
userhome, "soundbank-emg.sf2");
if (emg_soundbank_file.exists())
return null;
return new FileOutputStream(
emg_soundbank_file);
} catch (IOException e) {
} catch (SecurityException e) {
.doPrivileged((PrivilegedAction<OutputStream>) () -> {
try {
File userhome = new File(System
.getProperty("user.home"), ".gervill");
if (!userhome.exists()) {
userhome.mkdirs();
}
return null;
File emg_soundbank_file = new File(
userhome, "soundbank-emg.sf2");
if (emg_soundbank_file.exists()) {
return null;
}
return new FileOutputStream(emg_soundbank_file);
} catch (final FileNotFoundException ignored) {
}
return null;
});
if (out != null) {
try {
((SF2Soundbank) defaultSoundBank).save(out);
out.close();
} catch (IOException e) {
} catch (final IOException ignored) {
}
}
}
......@@ -846,26 +844,24 @@ public final class SoftSynthesizer implements AudioSynthesizer,
private Properties getStoredProperties() {
return AccessController
.doPrivileged(new PrivilegedAction<Properties>() {
public Properties run() {
Properties p = new Properties();
String notePath = "/com/sun/media/sound/softsynthesizer";
try {
Preferences prefroot = Preferences.userRoot();
if (prefroot.nodeExists(notePath)) {
Preferences prefs = prefroot.node(notePath);
String[] prefs_keys = prefs.keys();
for (String prefs_key : prefs_keys) {
String val = prefs.get(prefs_key, null);
if (val != null)
p.setProperty(prefs_key, val);
.doPrivileged((PrivilegedAction<Properties>) () -> {
Properties p = new Properties();
String notePath = "/com/sun/media/sound/softsynthesizer";
try {
Preferences prefroot = Preferences.userRoot();
if (prefroot.nodeExists(notePath)) {
Preferences prefs = prefroot.node(notePath);
String[] prefs_keys = prefs.keys();
for (String prefs_key : prefs_keys) {
String val = prefs.get(prefs_key, null);
if (val != null) {
p.setProperty(prefs_key, val);
}
}
} catch (BackingStoreException e) {
} catch (SecurityException e) {
}
return p;
} catch (final BackingStoreException ignored) {
}
return p;
});
}
......@@ -1044,7 +1040,6 @@ public final class SoftSynthesizer implements AudioSynthesizer,
return;
}
synchronized (control_mutex) {
Throwable causeException = null;
try {
if (line != null) {
// can throw IllegalArgumentException
......@@ -1117,24 +1112,17 @@ public final class SoftSynthesizer implements AudioSynthesizer,
weakstream.sourceDataLine = sourceDataLine;
}
} catch (LineUnavailableException e) {
causeException = e;
} catch (IllegalArgumentException e) {
causeException = e;
} catch (SecurityException e) {
causeException = e;
}
if (causeException != null) {
if (isOpen())
} catch (final LineUnavailableException | SecurityException
| IllegalArgumentException e) {
if (isOpen()) {
close();
}
// am: need MidiUnavailableException(Throwable) ctor!
MidiUnavailableException ex = new MidiUnavailableException(
"Can not open line");
ex.initCause(causeException);
ex.initCause(e);
throw ex;
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册