< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import sun.misc.ManagedLocalsThread;
  29 
  30 import java.io.BufferedInputStream;
  31 import java.io.InputStream;
  32 import java.io.File;
  33 import java.io.FileInputStream;
  34 
  35 import java.util.ArrayList;
  36 import java.util.Iterator;
  37 import java.util.List;
  38 import java.util.Properties;
  39 import java.util.ServiceLoader;
  40 
  41 import java.security.AccessController;
  42 import java.security.PrivilegedAction;
  43 
  44 import javax.sound.sampled.AudioPermission;
  45 
  46 /** Managing security in the Java Sound implementation.
  47  * This class contains all code that uses and is used by
  48  * SecurityManager.doPrivileged().
  49  *


 128                 properties.load(bin);
 129             } finally {
 130                 if (in != null) {
 131                     in.close();
 132                 }
 133             }
 134         } catch (Throwable t) {
 135             if (Printer.trace) {
 136                 System.err.println("Could not load properties file \"" + fname + "\"");
 137                 t.printStackTrace();
 138             }
 139         }
 140         if(Printer.trace)Printer.trace("<< JSSecurityManager: loadPropertiesImpl() completed");
 141     }
 142 
 143     /** Create a Thread in the current ThreadGroup.
 144      */
 145     static Thread createThread(final Runnable runnable,
 146                                final String threadName,
 147                                final boolean isDaemon, final int priority,
 148                                final boolean doStart) {
 149         Thread thread = new ManagedLocalsThread(runnable);


 150 
 151         if (threadName != null) {
 152             thread.setName(threadName);
 153         }
 154         thread.setDaemon(isDaemon);
 155         if (priority >= 0) {
 156             thread.setPriority(priority);
 157         }
 158         if (doStart) {
 159             thread.start();
 160         }
 161         return thread;
 162     }
 163 
 164     static synchronized <T> List<T> getProviders(final Class<T> providerClass) {
 165         List<T> p = new ArrayList<>(7);
 166         // ServiceLoader creates "lazy" iterator instance, but it ensures that
 167         // next/hasNext run with permissions that are restricted by whatever
 168         // creates the ServiceLoader instance, so it requires to be called from
 169         // privileged section
 170         final PrivilegedAction<Iterator<T>> psAction =
 171                 new PrivilegedAction<Iterator<T>>() {
 172                     @Override
 173                     public Iterator<T> run() {




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 


  28 import java.io.BufferedInputStream;
  29 import java.io.InputStream;
  30 import java.io.File;
  31 import java.io.FileInputStream;
  32 
  33 import java.util.ArrayList;
  34 import java.util.Iterator;
  35 import java.util.List;
  36 import java.util.Properties;
  37 import java.util.ServiceLoader;
  38 
  39 import java.security.AccessController;
  40 import java.security.PrivilegedAction;
  41 
  42 import javax.sound.sampled.AudioPermission;
  43 
  44 /** Managing security in the Java Sound implementation.
  45  * This class contains all code that uses and is used by
  46  * SecurityManager.doPrivileged().
  47  *


 126                 properties.load(bin);
 127             } finally {
 128                 if (in != null) {
 129                     in.close();
 130                 }
 131             }
 132         } catch (Throwable t) {
 133             if (Printer.trace) {
 134                 System.err.println("Could not load properties file \"" + fname + "\"");
 135                 t.printStackTrace();
 136             }
 137         }
 138         if(Printer.trace)Printer.trace("<< JSSecurityManager: loadPropertiesImpl() completed");
 139     }
 140 
 141     /** Create a Thread in the current ThreadGroup.
 142      */
 143     static Thread createThread(final Runnable runnable,
 144                                final String threadName,
 145                                final boolean isDaemon, final int priority,
 146                                final boolean doStart)
 147     {
 148         String name = (threadName != null) ? threadName : "JSSM Thread";
 149         Thread thread = new Thread(null, runnable, threadName, 0, false);
 150 



 151         thread.setDaemon(isDaemon);
 152         if (priority >= 0) {
 153             thread.setPriority(priority);
 154         }
 155         if (doStart) {
 156             thread.start();
 157         }
 158         return thread;
 159     }
 160 
 161     static synchronized <T> List<T> getProviders(final Class<T> providerClass) {
 162         List<T> p = new ArrayList<>(7);
 163         // ServiceLoader creates "lazy" iterator instance, but it ensures that
 164         // next/hasNext run with permissions that are restricted by whatever
 165         // creates the ServiceLoader instance, so it requires to be called from
 166         // privileged section
 167         final PrivilegedAction<Iterator<T>> psAction =
 168                 new PrivilegedAction<Iterator<T>>() {
 169                     @Override
 170                     public Iterator<T> run() {


< prev index next >