private InputStream getClassBytesStream(String internalName) throws IOException { InputStream is = null; // first look into platformCp final String resourceName = internalName + CLASS_RESOURCE_EXTENSION; Resource resource = myPlatformClasspath.getResource(resourceName, false); if (resource != null) { is = new ByteArrayInputStream(resource.getBytes()); } // second look into memory and classspath if (is == null) { is = lookupClassBeforeClasspath(internalName); } if (is == null) { resource = myClasspath.getResource(resourceName, false); if (resource != null) { is = new ByteArrayInputStream(resource.getBytes()); } } if (is == null) { is = lookupClassAfterClasspath(internalName); } return is; }
public InputStream getResourceAsStream(String resourceName) throws IOException { InputStream is = null; Resource resource = myPlatformClasspath.getResource(resourceName, false); if (resource != null) { is = new ByteArrayInputStream(resource.getBytes()); } if (is == null) { resource = myClasspath.getResource(resourceName, false); if (resource != null) { is = new ByteArrayInputStream(resource.getBytes()); } } return is; }
public Resource getResource(final String name, boolean check) { URL url = null; File file = null; try { url = new URL(getBaseURL(), name); if (!url.getFile().startsWith(getBaseURL().getFile())) { return null; } file = new File(myRootDir, name.replace('/', File.separatorChar)); if (!check || file.exists()) { // check means we load or process resource so we check its existence via old way return new FileResource(name, url, file, !check); } } catch (Exception exception) { if (!check && file != null && file.exists()) { try { // we can not open the file if it is directory, Resource still can be created return new FileResource(name, url, file, false); } catch (IOException ex) { } } } return null; }
/** * 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 */ protected Class<?> findClass(final String name) throws ClassNotFoundException { try { return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object 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(); } }
protected Class findClass(final String name) throws ClassNotFoundException { try { return (Class) AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException { String path = name.replace('.', '/').concat(".class"); Resource res = ucp.getResource(path, false); if (res != null) { if (TRACE) System.out.println("Hijacked! " + res); 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(); } }
/** * 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 * @throws ClassNotFoundException if the class could not be found, * or if the loader is closed. * @throws NullPointerException if {@code name} is {@code null}. */ @Override @SneakyThrows(ReflectiveOperationException.class) protected Class<?> findClass(String name) throws ClassNotFoundException { String path = name.replace('.', '/') + ".class"; Field ucpField = URLClassLoader.class.getDeclaredField("ucp"); ucpField.setAccessible(true); Resource res = ((URLClassPath) ucpField.get(this)).getResource(path, false); if (res != null) { try { return defineClass(name, res); } catch (IOException e) { throw new ClassNotFoundException(name, e); } } else { throw new ClassNotFoundException(name); } }
/** * 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(); } }
/** * 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(); } }
private Class defineClass(String name, Resource res) throws IOException { int i = name.lastIndexOf('.'); if (i != -1) { String pkgname = name.substring(0, i); // Check if package already loaded. Package pkg = getPackage(pkgname); if (pkg == null) { try { definePackage(pkgname, null, null, null, null, null, null, null); } catch (IllegalArgumentException e) { // do nothing, package already defined by some other thread } } } byte[] b = res.getBytes(); return _defineClass(name, b); }
private SandboxLoader doGetSubLoaderByClassContext(String clazz) { String path = clazz.replace('.', '/').concat(".class"); for(Entry<URLClassPath, SandboxLoader> e : subLoaderByJar.entrySet()){ Resource res = e.getKey().getResource(path, false); if (res != null) return e.getValue(); } SandboxLoader subLoader = subLoaderCache.get(clazz); if(null != subLoader) return subLoader; for(String prefix : subLoaderPrefixCache.keySet()) if(clazz.startsWith(prefix)) return subLoaderPrefixCache.get(prefix); return null; }
private boolean bypassClazz(String name) { if(null != enhancer && enhancer.isLoadClassWithApplicationLoader(name)) return true; if(classesToLoadWithParent.contains(name)) return ! prohibitBypass(name); for(String bp : classesByPrefixToLoadWithParent) if(name.startsWith(bp)) return ! prohibitBypass(name); /* check if it comes from an available jar */ if(! name.startsWith("java.") && null != bypassUcp){ String path = name.replace('.', '/').concat(".class"); Resource res = bypassUcp.getResource(path, false); if (res != null) return ! prohibitBypass(name); } return false; }
/** * Replica of parent {@link URLClassLoader} and {@link ClassLoader} class * method for other method * * @return {@link URL} */ private static Enumeration<URL> getBootstrapResources(String name) throws IOException { Enumeration<URL> urls; // Enumeration to iterate over final Enumeration<Resource> resources = getBootstrapsResources(name); urls = new Enumeration<URL>() { public URL nextElement() { return (resources.nextElement()).getURL(); } public boolean hasMoreElements() { return resources.hasMoreElements(); } }; return urls; }
/** * 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(); } }; }
/** * 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; }
/** * Find resources from the VM's built-in classloader. */ private static Enumeration getBootstrapResources(String name) throws IOException { final Enumeration e = getBootstrapClassPath().getResources(name); return new Enumeration () { public Object nextElement() { return ((Resource)e.nextElement()).getURL(); } public boolean hasMoreElements() { return e.hasMoreElements(); } }; }
public Resource getResource(String s, boolean flag) { int i = 0; for (Loader loader; (loader = getLoader(i)) != null; i++) { Resource resource = loader.getResource(s, flag); if (resource != null) { return resource; } } return null; }
public Resource getResource(String name, boolean flag) { try { final ZipFile file = acquireZipFile(); if (file != null) { final ZipEntry entry = file.getEntry(name); if (entry != null) { return new JarResource(entry, new URL(getBaseURL(), name)); } } } catch (Exception e) { return null; } return null; }
@Override public Resource getResource(String name) { final String originalName = name; if (name.equals(SA_JDI_PROPERTIES_FILE_NAME) || name.startsWith(SA_JDI_PACKAGE_PREFIX)) { name = SA_JDI_JVM_PREFIX + "/" + name; } return new DelegatedResource(originalName, super.getResource(name)); }
@Override public Resource getResource(String name, boolean check) { final String originalName = name; if (name.equals(SA_JDI_PROPERTIES_FILE_NAME) || name.startsWith(SA_JDI_PACKAGE_PREFIX)) { name = SA_JDI_JVM_PREFIX + "/" + name; } return new DelegatedResource(originalName, super.getResource(name, check)); }