Search in sources :

Example 1 with Resource

use of sun.misc.Resource in project jdk8u_jdk by JetBrains.

the class SystemClassLoaderAction method getBootstrapResource.

/**
     * Find resources from the VM's built-in classloader.
     */
private static URL getBootstrapResource(String name) {
    URLClassPath ucp = getBootstrapClassPath();
    Resource res = ucp.getResource(name);
    return res != null ? res.getURL() : null;
}
Also used : URLClassPath(sun.misc.URLClassPath) Resource(sun.misc.Resource)

Example 2 with Resource

use of sun.misc.Resource in project quasar by puniverse.

the class QuasarURLClassLoader method instrument.

private Resource instrument(final String className, final Resource res) {
    final ClassLoader parent = this;
    return new Resource() {

        private byte[] instrumented;

        @Override
        public synchronized byte[] getBytes() throws IOException {
            if (instrumented == null) {
                final byte[] bytes;
                ByteBuffer bb = res.getByteBuffer();
                if (bb != null) {
                    final int size = bb.remaining();
                    bytes = new byte[size];
                    bb.get(bytes);
                } else
                    bytes = res.getBytes();
                try {
                    this.instrumented = instrumentor.instrumentClass(parent, className, bytes);
                } catch (Exception ex) {
                    if (MethodDatabase.isProblematicClass(className))
                        instrumentor.log(LogLevel.INFO, "Skipping problematic class instrumentation %s - %s %s", className, ex, Arrays.toString(ex.getStackTrace()));
                    else
                        instrumentor.error("Unable to instrument " + className, ex);
                    instrumented = bytes;
                }
            }
            return instrumented;
        }

        @Override
        public ByteBuffer getByteBuffer() throws IOException {
            return null;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            throw new AssertionError();
        }

        @Override
        public String getName() {
            return res.getName();
        }

        @Override
        public URL getURL() {
            return res.getURL();
        }

        @Override
        public URL getCodeSourceURL() {
            return res.getCodeSourceURL();
        }

        @Override
        public int getContentLength() throws IOException {
            return res.getContentLength();
        }

        @Override
        public Manifest getManifest() throws IOException {
            return res.getManifest();
        }

        @Override
        public Certificate[] getCertificates() {
            return res.getCertificates();
        }

        @Override
        public CodeSigner[] getCodeSigners() {
            return res.getCodeSigners();
        }
    };
}
Also used : Resource(sun.misc.Resource) URLClassLoader(java.net.URLClassLoader) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CodeSigner(java.security.CodeSigner) Certificate(java.security.cert.Certificate)

Example 3 with Resource

use of sun.misc.Resource in project quasar by puniverse.

the class QuasarURLClassLoaderHelper method instrument.

private Resource instrument(final String className, final Resource res) {
    return new Resource() {

        private byte[] instrumented;

        @Override
        public synchronized byte[] getBytes() throws IOException {
            if (instrumented == null) {
                final byte[] bytes;
                ByteBuffer bb = res.getByteBuffer();
                if (bb != null) {
                    final int size = bb.remaining();
                    bytes = new byte[size];
                    bb.get(bytes);
                } else
                    bytes = res.getBytes();
                try {
                    this.instrumented = instrumentor.instrumentClass(cl, className, bytes);
                } catch (Exception ex) {
                    if (MethodDatabase.isProblematicClass(className))
                        instrumentor.log(LogLevel.INFO, "Skipping problematic class instrumentation %s - %s %s", className, ex, Arrays.toString(ex.getStackTrace()));
                    else
                        instrumentor.error("Unable to instrument " + className, ex);
                    instrumented = bytes;
                }
            }
            return instrumented;
        }

        @Override
        public ByteBuffer getByteBuffer() throws IOException {
            return null;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            throw new AssertionError();
        }

        @Override
        public String getName() {
            return res.getName();
        }

        @Override
        public URL getURL() {
            return res.getURL();
        }

        @Override
        public URL getCodeSourceURL() {
            return res.getCodeSourceURL();
        }

        @Override
        public int getContentLength() throws IOException {
            return res.getContentLength();
        }

        @Override
        public Manifest getManifest() throws IOException {
            return res.getManifest();
        }

        @Override
        public Certificate[] getCertificates() {
            return res.getCertificates();
        }

        @Override
        public CodeSigner[] getCodeSigners() {
            return res.getCodeSigners();
        }
    };
}
Also used : Resource(sun.misc.Resource) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CodeSigner(java.security.CodeSigner) Certificate(java.security.cert.Certificate)

Example 4 with Resource

use of sun.misc.Resource in project intellij-community by JetBrains.

the class SystemClassLoaderAction method getBootstrapResource.

/**
     * Find resources from the VM's built-in classloader.
     */
private static URL getBootstrapResource(String name) {
    URLClassPath ucp = getBootstrapClassPath();
    Resource res = ucp.getResource(name);
    return res != null ? res.getURL() : null;
}
Also used : URLClassPath(sun.misc.URLClassPath) Resource(sun.misc.Resource)

Example 5 with Resource

use of sun.misc.Resource in project jdk8u_jdk by JetBrains.

the class FactoryURLClassLoader method findClass.

/**
     * 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;
}
Also used : Resource(sun.misc.Resource) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException)

Aggregations

Resource (sun.misc.Resource)5 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ByteBuffer (java.nio.ByteBuffer)2 CodeSigner (java.security.CodeSigner)2 Certificate (java.security.cert.Certificate)2 URLClassPath (sun.misc.URLClassPath)2 URLClassLoader (java.net.URLClassLoader)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1