Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxws/src/share/jaf_classes/javax/activation/SecuritySupport.java
38877 views
/*1* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.activation;2627import java.security.*;28import java.net.*;29import java.io.*;30import java.util.*;3132/**33* Security related methods that only work on J2SE 1.2 and newer.34*35* @since 1.636*/37class SecuritySupport {3839private SecuritySupport() {40// private constructor, can't create an instance41}4243public static ClassLoader getContextClassLoader() {44return (ClassLoader)45AccessController.doPrivileged(new PrivilegedAction() {46public Object run() {47ClassLoader cl = null;48try {49cl = Thread.currentThread().getContextClassLoader();50} catch (SecurityException ex) { }51return cl;52}53});54}5556public static InputStream getResourceAsStream(final Class c,57final String name) throws IOException {58try {59return (InputStream)60AccessController.doPrivileged(new PrivilegedExceptionAction() {61public Object run() throws IOException {62return c.getResourceAsStream(name);63}64});65} catch (PrivilegedActionException e) {66throw (IOException)e.getException();67}68}6970public static URL[] getResources(final ClassLoader cl, final String name) {71return (URL[])72AccessController.doPrivileged(new PrivilegedAction() {73public Object run() {74URL[] ret = null;75try {76List v = new ArrayList();77Enumeration e = cl.getResources(name);78while (e != null && e.hasMoreElements()) {79URL url = (URL)e.nextElement();80if (url != null)81v.add(url);82}83if (v.size() > 0) {84ret = new URL[v.size()];85ret = (URL[])v.toArray(ret);86}87} catch (IOException ioex) {88} catch (SecurityException ex) { }89return ret;90}91});92}9394public static URL[] getSystemResources(final String name) {95return (URL[])96AccessController.doPrivileged(new PrivilegedAction() {97public Object run() {98URL[] ret = null;99try {100List v = new ArrayList();101Enumeration e = ClassLoader.getSystemResources(name);102while (e != null && e.hasMoreElements()) {103URL url = (URL)e.nextElement();104if (url != null)105v.add(url);106}107if (v.size() > 0) {108ret = new URL[v.size()];109ret = (URL[])v.toArray(ret);110}111} catch (IOException ioex) {112} catch (SecurityException ex) { }113return ret;114}115});116}117118public static InputStream openStream(final URL url) throws IOException {119try {120return (InputStream)121AccessController.doPrivileged(new PrivilegedExceptionAction() {122public Object run() throws IOException {123return url.openStream();124}125});126} catch (PrivilegedActionException e) {127throw (IOException)e.getException();128}129}130}131132133