sun.misc.Resource Java Examples

The following examples show how to use sun.misc.Resource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: URLClassLoader.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 */
protected Class<?> findClass(final String name)
     throws ClassNotFoundException
{
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class>() {
                public Class run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        throw new ClassNotFoundException(name);
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
}
 
Example #2
Source File: URLClassLoader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
     throws ClassNotFoundException
{
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        throw new ClassNotFoundException(name);
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
}
 
Example #3
Source File: URLClassLoader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
     throws ClassNotFoundException
{
    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        throw new ClassNotFoundException(name);
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
}
 
Example #4
Source File: ClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #5
Source File: ClassLoader.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #6
Source File: URLClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #7
Source File: ClassLoader.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #8
Source File: URLClassLoader.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #9
Source File: ClassLoader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #10
Source File: URLClassLoader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #11
Source File: ClassLoader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #12
Source File: ClassLoader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #13
Source File: ClassLoader.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #14
Source File: URLClassLoader.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #15
Source File: ClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #16
Source File: URLClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #17
Source File: ClassLoader.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #18
Source File: ClassLoader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #19
Source File: URLClassLoader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #20
Source File: LauncherBootLoader.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public URL findResource(String name) {
    final Resource res = bootstrapClassPath.getResource(name);
    if (res == null) {
        return null;
    }
    return res.getURL();
}
 
Example #21
Source File: ClassLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #22
Source File: ClassLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #23
Source File: URLClassLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #24
Source File: URLClassLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #25
Source File: ClassLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}
 
Example #26
Source File: URLClassLoader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #27
Source File: URLClassLoader.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #28
Source File: URLClassLoader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #29
Source File: URLClassLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finds and loads the class with the specified name from the URL search
 * path. Any URLs referring to JAR files are loaded and opened as needed
 * until the class is found.
 *
 * @param name the name of the class
 * @return the resulting class
 * @exception ClassNotFoundException if the class could not be found,
 *            or if the loader is closed.
 * @exception NullPointerException if {@code name} is {@code null}.
 */
protected Class<?> findClass(final String name)
    throws ClassNotFoundException
{
    final Class<?> result;
    try {
        result = AccessController.doPrivileged(
            new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    String path = name.replace('.', '/').concat(".class");
                    Resource res = ucp.getResource(path, false);
                    if (res != null) {
                        try {
                            return defineClass(name, res);
                        } catch (IOException e) {
                            throw new ClassNotFoundException(name, e);
                        }
                    } else {
                        return null;
                    }
                }
            }, acc);
    } catch (java.security.PrivilegedActionException pae) {
        throw (ClassNotFoundException) pae.getException();
    }
    if (result == null) {
        throw new ClassNotFoundException(name);
    }
    return result;
}
 
Example #30
Source File: ClassLoader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Find resources from the VM's built-in classloader.
 */
private static Enumeration<URL> getBootstrapResources(String name)
    throws IOException
{
    final Enumeration<Resource> e =
        getBootstrapClassPath().getResources(name);
    return new Enumeration<URL> () {
        public URL nextElement() {
            return e.nextElement().getURL();
        }
        public boolean hasMoreElements() {
            return e.hasMoreElements();
        }
    };
}