Search in sources :

Example 21 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$ClassReader in project tomee by apache.

the class DependenceValidationTest method file.

private static void file(final File file, final DependencyVisitor dependencyVisitor) {
    try {
        final InputStream in = IO.read(file);
        try {
            final ClassReader classReader = new ClassReader(in);
            classReader.accept(dependencyVisitor, ClassWriter.COMPUTE_MAXS);
        } finally {
            IO.close(in);
        }
    } catch (final IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm5.ClassReader) IOException(java.io.IOException)

Example 22 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$ClassReader in project component-runtime by Talend.

the class ProxyGenerator method findJavaVersion.

private int findJavaVersion(final Class<?> from) {
    final String resource = from.getName().replace('.', '/') + ".class";
    try (final InputStream stream = from.getClassLoader().getResourceAsStream(resource)) {
        if (stream == null) {
            return javaVersion;
        }
        final ClassReader reader = new ClassReader(stream);
        final VersionVisitor visitor = new VersionVisitor();
        reader.accept(visitor, SKIP_DEBUG);
        if (visitor.version != 0) {
            return visitor.version;
        }
    } catch (final Exception e) {
    // no-op
    }
    // version
    return javaVersion;
}
Also used : InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm6.ClassReader) ObjectStreamException(java.io.ObjectStreamException)

Example 23 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$ClassReader in project component-runtime by Talend.

the class BeamIOTransformer method rewrite.

private byte[] rewrite(final ConfigurableClassLoader loader, final String className, final byte[] classfileBuffer, final ClassLoader tmpLoader) {
    final String plugin = loader.getId();
    final ClassReader reader = new ClassReader(classfileBuffer);
    final ComponentClassWriter writer = new ComponentClassWriter(className.replace('/', '.'), tmpLoader, reader, ClassWriter.COMPUTE_FRAMES);
    final ComponentClassVisitor visitor = new ComponentClassVisitor(writer, plugin);
    reader.accept(visitor, ClassReader.SKIP_FRAMES);
    return writer.toByteArray();
}
Also used : ClassReader(org.apache.xbean.asm6.ClassReader)

Example 24 with net.sf.cglib.asm.$ClassReader

use of net.sf.cglib.asm.$ClassReader in project apex-core by apache.

the class FastClassIndexReaderTest method testPerformance.

@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);
            // FastClassSignatureReader fastClassSignatureReader = new FastClassSignatureReader(ins);
            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);
}
Also used : InputStream(java.io.InputStream) ClassReader(org.apache.xbean.asm5.ClassReader) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)15 InputStream (java.io.InputStream)12 ClassReader (org.apache.xbean.asm5.ClassReader)11 ClassReader (org.apache.xbean.asm6.ClassReader)8 JarEntry (java.util.jar.JarEntry)5 ClassReader (jodd.asm5.ClassReader)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional.ofNullable (java.util.Optional.ofNullable)3 JarOutputStream (java.util.jar.JarOutputStream)3 Stream (java.util.stream.Stream)3 EXPAND_FRAMES (org.apache.xbean.asm6.ClassReader.EXPAND_FRAMES)3 ClassWriter (org.apache.xbean.asm6.ClassWriter)3 COMPUTE_FRAMES (org.apache.xbean.asm6.ClassWriter.COMPUTE_FRAMES)3 ClassRemapper (org.apache.xbean.asm6.commons.ClassRemapper)3 Remapper (org.apache.xbean.asm6.commons.Remapper)3