@Test public void testFindClass() throws Exception { System.out.println("findClass"); Class c1,c2; try { c1 = Class.forName("javax.xml.ws.Service", false, pwcl); Assert.assertTrue(c1.getDeclaredMethods().length < 3); } catch (ClassNotFoundException cnfe) { Assert.fail(); } try { c2 = Class.forName("javax.xml.ws.Service", false, Thread.currentThread().getContextClassLoader()); Assert.assertTrue(c2.getDeclaredMethods().length < 3); } catch (ClassNotFoundException cnfe) { Assert.fail(); } }
@Override protected Class findClass(String name) throws ClassNotFoundException { StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6); sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); } InputStream is = null; URLConnection con = null; try { con = u.openConnection(); is = con.getInputStream(); } catch (IOException ioe) { throw new ClassNotFoundException(name); } if (is==null) throw new ClassNotFoundException(name); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while((len=is.read(buf))>=0) baos.write(buf,0,len); buf = baos.toByteArray(); int packIndex = name.lastIndexOf('.'); if (packIndex != -1) { String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); } } return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e); } finally { try { if (con instanceof JarURLConnection) { jars.add(((JarURLConnection) con).getJarFile()); } } catch (IOException ioe) { } if (is != null) { try { is.close(); } catch (IOException ioe) { } } } }
ParallelWorldClassLoader extends ClassLoader implements Closeable { @Override protected Class findClass(String name) throws ClassNotFoundException { StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6); sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); } InputStream is = null; URLConnection con = null; try { con = u.openConnection(); is = con.getInputStream(); } catch (IOException ioe) { throw new ClassNotFoundException(name); } if (is==null) throw new ClassNotFoundException(name); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while((len=is.read(buf))>=0) baos.write(buf,0,len); buf = baos.toByteArray(); int packIndex = name.lastIndexOf('.'); if (packIndex != -1) { String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); } } return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e); } finally { try { if (con instanceof JarURLConnection) { jars.add(((JarURLConnection) con).getJarFile()); } } catch (IOException ioe) { } if (is != null) { try { is.close(); } catch (IOException ioe) { } } } } }
ParallelWorldClassLoader extends ClassLoader implements Closeable { @Override protected Class findClass(String name) throws ClassNotFoundException { StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6); sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); } InputStream is = null; URLConnection con = null; try { con = u.openConnection(); is = con.getInputStream(); } catch (IOException ioe) { throw new ClassNotFoundException(name); } if (is==null) throw new ClassNotFoundException(name); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while((len=is.read(buf))>=0) baos.write(buf,0,len); buf = baos.toByteArray(); int packIndex = name.lastIndexOf('.'); if (packIndex != -1) { String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); } } return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e); } finally { try { if (con instanceof JarURLConnection) { jars.add(((JarURLConnection) con).getJarFile()); } } catch (IOException ioe) { } if (is != null) { try { is.close(); } catch (IOException ioe) { } } } } ParallelWorldClassLoader(ClassLoader parent,String prefix); }
ParallelWorldClassLoader extends ClassLoader implements Closeable { @Override protected Class findClass(String name) throws ClassNotFoundException { StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6); sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); } InputStream is = null; URLConnection con = null; try { con = u.openConnection(); is = con.getInputStream(); } catch (IOException ioe) { throw new ClassNotFoundException(name); } if (is==null) throw new ClassNotFoundException(name); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while((len=is.read(buf))>=0) baos.write(buf,0,len); buf = baos.toByteArray(); int packIndex = name.lastIndexOf('.'); if (packIndex != -1) { String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); } } return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e); } finally { try { if (con instanceof JarURLConnection) { jars.add(((JarURLConnection) con).getJarFile()); } } catch (IOException ioe) { } if (is != null) { try { is.close(); } catch (IOException ioe) { } } } } ParallelWorldClassLoader(ClassLoader parent,String prefix); @Override synchronized void close(); static URL toJarUrl(URL res); }
ParallelWorldClassLoader extends ClassLoader implements Closeable { @Override protected Class findClass(String name) throws ClassNotFoundException { StringBuffer sb = new StringBuffer(name.length()+prefix.length()+6); sb.append(prefix).append(name.replace('.','/')).append(".class"); URL u = getParent().getResource(sb.toString()); if (u == null) { throw new ClassNotFoundException(name); } InputStream is = null; URLConnection con = null; try { con = u.openConnection(); is = con.getInputStream(); } catch (IOException ioe) { throw new ClassNotFoundException(name); } if (is==null) throw new ClassNotFoundException(name); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while((len=is.read(buf))>=0) baos.write(buf,0,len); buf = baos.toByteArray(); int packIndex = name.lastIndexOf('.'); if (packIndex != -1) { String pkgname = name.substring(0, packIndex); Package pkg = getPackage(pkgname); if (pkg == null) { definePackage(pkgname, null, null, null, null, null, null, null); } } return defineClass(name,buf,0,buf.length); } catch (IOException e) { throw new ClassNotFoundException(name,e); } finally { try { if (con instanceof JarURLConnection) { jars.add(((JarURLConnection) con).getJarFile()); } } catch (IOException ioe) { } if (is != null) { try { is.close(); } catch (IOException ioe) { } } } } ParallelWorldClassLoader(ClassLoader parent,String prefix); @Override synchronized void close(); static URL toJarUrl(URL res);  }