You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClassPoolBench.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package javassist;
  2. import java.util.Enumeration;
  3. import java.util.zip.*;
  4. public class ClassPoolBench {
  5. static ClassPool cp;
  6. static boolean mod = false, detach = false, readonly = false;
  7. public static void accessClass(String name) throws Exception {
  8. CtClass cc = cp.get(name);
  9. System.out.println(cc.getName());
  10. cc.getSuperclass();
  11. if (mod)
  12. cc.getClassFile();
  13. if (detach)
  14. cc.stopPruning(true);
  15. if (!readonly)
  16. cc.toBytecode();
  17. if (detach)
  18. cc.detach();
  19. }
  20. @SuppressWarnings("rawtypes")
  21. public static void accessAll(String filename) throws Exception {
  22. ZipFile zip = new ZipFile(filename);
  23. Enumeration files = zip.entries();
  24. while (files.hasMoreElements()) {
  25. ZipEntry z = (ZipEntry)files.nextElement();
  26. String name = z.getName();
  27. if (name.endsWith(".class")) {
  28. name = name.substring(0, name.length() - 6)
  29. .replace('/', '.');
  30. accessClass(name);
  31. }
  32. }
  33. zip.close();
  34. }
  35. public static void main(String[] args) throws Exception {
  36. cp = ClassPool.getDefault();
  37. cp.appendClassPath(args[0]);
  38. if (args[1].equals("true"))
  39. mod = true;
  40. else if (args[1].equals("detach"))
  41. mod = detach = true;
  42. else if (args[1].equals("read"))
  43. readonly = true;
  44. System.err.println("mod: " + mod + " detach: " + detach
  45. + " readonly: " + readonly);
  46. accessAll(args[0]);
  47. }
  48. }