Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.jar.*;
- import java.util.zip.*;
- public class JavaApplication1 {
- private static class MyClassLoader extends ClassLoader {
- public Class<?> myDefineClass(byte[] b, int off, int len) {
- return defineClass(b, off, len);
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String path = sc.nextLine();
- byte[] buf = new byte[1024*1024*50];
- MyClassLoader loader = new MyClassLoader();
- int cls = 0, intfs = 0, enums = 0;
- try {
- ZipInputStream zis = new ZipInputStream(new FileInputStream(path));
- while (true) {
- ZipEntry en = zis.getNextEntry();
- //System.out.println("entry: " + en);
- if (null == en)
- break;
- if (en.toString() == null ||
- !en.toString().endsWith("class"))
- continue;
- int bytesRead = 0;
- while (true) {
- int lastRead = zis.read(buf, bytesRead, 1024);
- if (-1 == lastRead)
- break;
- bytesRead += lastRead;
- }
- try {
- Class c = loader.myDefineClass(buf, 0, bytesRead);
- if (c.isInterface())
- ++intfs;
- else if (c.isEnum())
- ++enums;
- else
- ++cls;
- }
- catch (Error e) {
- //System.out.println("!!!");
- //e.printStackTrace();
- }
- //System.out.println("a class defined!");
- }
- } catch (Exception ex) {
- //System.out.println("???");
- //ex.printStackTrace();
- cls = -1;
- }
- System.out.print(cls);
- if(cls != -1)
- System.out.print(" " + intfs + " " + enums);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement