JarHandler.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * (c) copyright John Gough, 2012-2017
  3. */
  4. package j2cps;
  5. import java.io.InputStream;
  6. import java.io.IOException;
  7. //import java.util.HashMap;
  8. //import java.util.ArrayList;
  9. import java.util.Enumeration;
  10. import java.util.jar.JarFile;
  11. import java.util.jar.JarEntry;
  12. /**
  13. *
  14. * @author john
  15. */
  16. public class JarHandler {
  17. public JarHandler( ) { }
  18. public void ProcessJar( JarFile jf ){
  19. System.out.printf("INFO: opened jar file <%s>\n", jf.getName());
  20. Enumeration<JarEntry> entries = jf.entries();
  21. String classFileName;
  22. String className;
  23. while (entries.hasMoreElements()) {
  24. JarEntry entry = entries.nextElement();
  25. classFileName = entry.getName();
  26. //System.out.println(entryName);
  27. if (classFileName.toLowerCase().endsWith(".class")) {
  28. className = classFileName.substring(0, classFileName.length() - 6);
  29. try {
  30. ClassDesc desc = ClassDesc.MakeNewClassDesc(className, null);
  31. desc.parentPkg.myClasses.add(desc);
  32. desc.parentPkg.processed = true;
  33. InputStream classStream = jf.getInputStream( entry );
  34. boolean ok = desc.ReadJarClassFile(classStream);
  35. if (ClassDesc.verbose)
  36. System.out.printf( "Read jar class %s ... %s\n", className, (ok ? "OK" : "error"));
  37. } catch (IOException x) {
  38. // Message
  39. System.err.println( "ProcessJar threw IOException");
  40. System.err.println( x.getMessage() );
  41. // x.printStackTrace();
  42. System.exit(1);
  43. }
  44. }
  45. }
  46. //
  47. // At this point all the class files in the jar have
  48. // been processed, and all packages listed in the todo
  49. // collection. However, dependent packages have not been
  50. // processed.
  51. //
  52. }
  53. }