FastClassIndexReader { public String getName() { return name; } FastClassIndexReader(final InputStream is); int readUnsignedShort(final int index); short readShort(final int index); int readInt(final int index); String readClass(final int index); String readUTF8(int index); String getName(); String getSuperName(); String[] getInterfaces(); boolean isInstantiable(); static final byte[] DEFAULT_CONSTRUCTOR_NAME; static final byte[] DEFAULT_CONSTRUCTOR_DESC; }
@Test public void testPerformance() throws Exception { String javahome = System.getProperty("java.home"); String jdkJar = javahome + "/lib/rt.jar"; JarFile jar = new JarFile(jdkJar); java.util.Enumeration<JarEntry> entriesEnum = jar.entries(); long time = System.currentTimeMillis(); while (entriesEnum.hasMoreElements()) { JarEntry jarEntry = entriesEnum.nextElement(); if (jarEntry.getName().endsWith("class")) { InputStream ins = jar.getInputStream(jarEntry); ClassReader classReader = new ClassReader(ins); ClassNodeType classN = new ClassNodeType(); classReader.accept(classN, ClassReader.SKIP_CODE); CompactClassNode ccn = CompactUtil.compactClassNode(classN); ins.close(); } } LOG.info("The time to scan jdk using ASM ClassReader {} ", System.currentTimeMillis() - time); jar.close(); jar = new JarFile(jdkJar); entriesEnum = jar.entries(); time = System.currentTimeMillis(); while (entriesEnum.hasMoreElements()) { JarEntry jarEntry = entriesEnum.nextElement(); if (jarEntry.getName().endsWith("class")) { InputStream ins = jar.getInputStream(jarEntry); FastClassIndexReader fastClassIndexReader = new FastClassIndexReader(ins); ins.close(); } } jar.close(); LOG.info("The time to scan jdk using FastClassIndexReader {} ", System.currentTimeMillis() - time); }