List of usage examples for java.lang ClassNotFoundException ClassNotFoundException
public ClassNotFoundException(String s)
ClassNotFoundException
with the specified detail message. From source file:org.blocks4j.reconf.client.i18n.MessagedBundleTest.java
@Test public void test() throws Exception { for (Entry<String, List<String>> each : basePackageBundles.entrySet()) { for (String path : each.getValue()) { Properties props = new Properties(); props.load(this.getClass().getResourceAsStream(path)); for (Object key : props.keySet()) { List<String> parts = Arrays.asList(StringUtils.split(each.getKey() + key.toString(), ".")); boolean found = false; for (int i = 0; i < parts.size(); i++) { String className = StringUtils.join(parts.subList(0, i), "."); try { Class.forName(className); found = true;/* w ww .ja v a 2 s. com*/ break; } catch (ClassNotFoundException e) { } } if (!found) { throw new ClassNotFoundException(each.getKey() + key.toString() + " at " + path); } } } } }
From source file:org.gradle.internal.classloader.TransformingClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (!shouldTransform(name)) { return super.findClass(name); }/* w w w . ja v a2 s . co m*/ String resourceName = name.replace('.', '/') + ".class"; URL resource = findResource(resourceName); byte[] bytes; CodeSource codeSource; try { if (resource != null) { bytes = loadBytecode(resource); bytes = transform(name, bytes); URL codeBase = ClasspathUtil.getClasspathForResource(resource, resourceName).toURI().toURL(); codeSource = new CodeSource(codeBase, (Certificate[]) null); } else { bytes = generateMissingClass(name); codeSource = null; } } catch (Exception e) { throw new GradleException(String.format("Could not load class '%s' from %s.", name, resource), e); } if (bytes == null) { throw new ClassNotFoundException(name); } String packageName = StringUtils.substringBeforeLast(name, "."); Package p = getPackage(packageName); if (p == null) { definePackage(packageName, null, null, null, null, null, null, null); } return defineClass(name, bytes, 0, bytes.length, codeSource); }
From source file:com.opensymphony.webwork.util.classloader.stores.ResourceStoreClassLoader.java
protected Class findClass(final String name) throws ClassNotFoundException { final Class clazz = fastFindClass(name); if (clazz == null) { throw new ClassNotFoundException(name); }/*from ww w .j ava 2s . com*/ return clazz; }
From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.JarsClassLoader.java
protected Class findClass(String name) throws ClassNotFoundException { String path = name.replace('.', '/').concat(".class"); JarFileEntry entry = findPath(path); if (entry == null) { throw new ClassNotFoundException(name); }/* w w w . j a va 2 s . c o m*/ //TODO certificates, package byte[] classData; try { long size = entry.getSize(); if (size >= 0) { classData = DataContainerStreamUtil.readData(entry.getInputStream(), (int) size); } else { classData = DataContainerStreamUtil.readData(entry.getInputStream()); } } catch (IOException e) { log.debug(e, e); throw new ClassNotFoundException(name, e); } return defineClass(name, classData, 0, classData.length, protectionDomain); }
From source file:com.google.code.ddom.commons.cl.ClassRef.java
public InputStream getClassDefinitionAsStream() throws ClassNotFoundException { String resourceName = ClassLoaderUtils.getResourceNameForClassName(className); InputStream in = classLoader.getResourceAsStream(resourceName); if (in == null) { throw new ClassNotFoundException(className); } else {// w ww . j av a 2 s. c o m return in; } }
From source file:org.impalaframework.spring.classloader.CustomURLClassLoader.java
public Class<?> loadClass(String className) throws ClassNotFoundException { try {//from w w w .jav a 2 s.co m Class<?> parentClass = getParent().loadClass(className); if (logger.isDebugEnabled()) logger.debug("Returning system class: " + parentClass); return parentClass; } catch (Exception e) { } try { Class<?> loadedClass = loadedClasses.get(className); if (loadedClass != null) { if (logger.isDebugEnabled()) logger.debug("Returning already loaded custom class: " + className); return loadedClass; } Class<?> result = findClass(className); loadedClasses.put(className, result); return result; } catch (Exception e) { } if (logger.isDebugEnabled()) logger.debug("Class not found: " + className); throw new ClassNotFoundException(className); }
From source file:org.vosao.business.impl.plugin.PluginClassLoader.java
@Override public Class findClass(String name) throws ClassNotFoundException { Class cls = findLoadedClass(name); if (cls != null) { return cls; }//from w w w . ja v a2 s.c o m try { byte[] b = findPluginResource(name); if (b == null) { throw new ClassNotFoundException(name); } return defineClass(name, b, 0, b.length); } catch (SecurityException e) { return super.loadClass(name); } }
From source file:org.sonar.java.bytecode.loader.SquidClassLoader.java
@Override protected Class findClass(String name) throws ClassNotFoundException { String resourceName = name.replace('.', '/') + ".class"; for (Loader loader : loaders) { byte[] classBytes = loader.loadBytes(resourceName); if (ArrayUtils.isNotEmpty(classBytes)) { // TODO Godin: definePackage ? return defineClass(name, classBytes, 0, classBytes.length); }//from ww w. j a v a 2 s.com } throw new ClassNotFoundException(name); }
From source file:framework.ResourceStoreClassLoader.java
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { // log.debug(getId() + " looking for: " + name); Class clazz = findLoadedClass(name); if (clazz == null) { clazz = fastFindClass(name);//from w ww . j av a 2 s .c o m if (clazz == null) { final ClassLoader parent = getParent(); if (parent != null) { clazz = parent.loadClass(name); // log.debug(getId() + " delegating loading to parent: " + // name); } else { throw new ClassNotFoundException(name); } } else { // log.debug(getId() + " loaded from store: " + name); } } if (resolve) { resolveClass(clazz); } return clazz; }
From source file:MainClass.java
private byte[] loadClassData(String name) throws ClassNotFoundException { byte[] buffer; InputStream theClassInputStream = null; int bufferLength = 128; try {/*from w w w . j a v a2s . c o m*/ URL classURL = new URL(url, name + ".class"); URLConnection uc = classURL.openConnection(); uc.setAllowUserInteraction(false); try { theClassInputStream = uc.getInputStream(); } catch (NullPointerException e) { System.err.println(e); throw new ClassNotFoundException(name + " input stream problem"); } int contentLength = uc.getContentLength(); // A lot of web servers don't send content-lengths // for .class files if (contentLength == -1) { buffer = new byte[bufferLength * 16]; } else { buffer = new byte[contentLength]; } int bytesRead = 0; int offset = 0; while (bytesRead >= 0) { bytesRead = theClassInputStream.read(buffer, offset, bufferLength); if (bytesRead == -1) break; offset += bytesRead; if (contentLength == -1 && offset == buffer.length) { // grow the array byte temp[] = new byte[offset * 2]; System.arraycopy(buffer, 0, temp, 0, offset); buffer = temp; } else if (offset > buffer.length) { throw new ClassNotFoundException(name + " error reading data into the array"); } } if (offset < buffer.length) { // shrink the array byte temp[] = new byte[offset]; System.arraycopy(buffer, 0, temp, 0, offset); buffer = temp; } // Make sure all the bytes were received if (contentLength != -1 && offset != contentLength) { throw new ClassNotFoundException("Only " + offset + " bytes received for " + name + "\n Expected " + contentLength + " bytes"); } } catch (Exception e) { throw new ClassNotFoundException(name + " " + e); } finally { try { if (theClassInputStream != null) theClassInputStream.close(); } catch (IOException e) { } } return buffer; }