Package org.objectweb.asm

Examples of org.objectweb.asm.ClassReader


      ClassLoader loader,
      String className,
      Class classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer) {
    ClassReader reader;
    try {
      reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
    }
    catch (IOException e) {
      log.error( "Unable to read class", e );
      throw new HibernateException( "Unable to read class: " + e.getMessage() );
    }

    String[] names = ClassNameReader.getClassInfo( reader );
    ClassWriter w = new DebuggingClassWriter( ClassWriter.COMPUTE_MAXS  );
    ClassTransformer t = getClassTransformer( names );
    if ( t != null ) {
      if ( log.isDebugEnabled() ) {
        log.debug( "Enhancing " + className );
      }
      ByteArrayOutputStream out;
      byte[] result;
      try {
        reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
        new TransformingClassGenerator(
            new ClassReaderGenerator( reader, skipDebug() ), t
        ).generateClass( w );
        out = new ByteArrayOutputStream();
        out.write( w.toByteArray() );
View Full Code Here


    private final String name;
    private final boolean isInstrumented;

    public CustomClassDescriptor(byte[] bytecode) throws Exception {
      this.bytecode = bytecode;
      ClassReader reader = new ClassReader( new ByteArrayInputStream( bytecode ) );
      String[] names = ClassNameReader.getClassInfo( reader );
      this.name = names[0];
      boolean instrumented = false;
      for ( int i = 1; i < names.length; i++ ) {
        if ( InterceptFieldEnabled.class.getName().equals( names[i] ) ) {
View Full Code Here

    private final String name;
    private final boolean isInstrumented;

    public CustomClassDescriptor(byte[] bytecode) throws Exception {
      this.bytecode = bytecode;
      ClassReader reader = new ClassReader( new ByteArrayInputStream( bytecode ) );
      String[] names = ClassNameReader.getClassInfo( reader );
      this.name = names[0];
      boolean instrumented = false;
      for ( int i = 1; i < names.length; i++ ) {
        if ( InterceptFieldEnabled.class.getName().equals( names[i] ) ) {
View Full Code Here

    private final String name;
    private final boolean isInstrumented;

    public CustomClassDescriptor(byte[] bytecode) throws Exception {
      this.bytecode = bytecode;
      ClassReader reader = new ClassReader( new ByteArrayInputStream( bytecode ) );
      String[] names = ClassNameReader.getClassInfo( reader );
      this.name = names[0];
      boolean instrumented = false;
      for ( int i = 1; i < names.length; i++ ) {
        if ( InterceptFieldEnabled.class.getName().equals( names[i] ) ) {
View Full Code Here

      ClassLoader loader,
      String className,
      Class classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer) {
    ClassReader reader;
    try {
      reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
    }
    catch (IOException e) {
      log.error( "Unable to read class", e );
      throw new HibernateException( "Unable to read class: " + e.getMessage() );
    }

    String[] names = ClassNameReader.getClassInfo( reader );
    ClassWriter w = new DebuggingClassWriter( ClassWriter.COMPUTE_MAXS  );
    ClassTransformer t = getClassTransformer( names );
    if ( t != null ) {
      if ( log.isDebugEnabled() ) {
        log.debug( "Enhancing " + className );
      }
      ByteArrayOutputStream out;
      byte[] result;
      try {
        reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
        new TransformingClassGenerator(
            new ClassReaderGenerator( reader, skipDebug() ), t
        ).generateClass( w );
        out = new ByteArrayOutputStream();
        out.write( w.toByteArray() );
View Full Code Here

      ClassLoader loader,
      String className,
      Class classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer) {
    ClassReader reader;
    try {
      reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
    }
    catch (IOException e) {
      log.error( "Unable to read class", e );
      throw new HibernateException( "Unable to read class: " + e.getMessage() );
    }

    String[] names = ClassNameReader.getClassInfo( reader );
    ClassWriter w = new DebuggingClassWriter( true );
    ClassTransformer t = getClassTransformer( names );
    if ( t != null ) {
      if ( log.isDebugEnabled() ) {
        log.debug( "Enhancing " + className );
      }
      ByteArrayOutputStream out;
      byte[] result;
      try {
        reader = new ClassReader( new ByteArrayInputStream( classfileBuffer ) );
        new TransformingClassGenerator(
            new ClassReaderGenerator( reader, attributes(), skipDebug() ), t
        ).generateClass( w );
        out = new ByteArrayOutputStream();
        out.write( w.toByteArray() );
View Full Code Here

  }

  byte[] nullAdaptClass (final InputStream is, final String name)
    throws Exception
  {
    ClassReader cr = new ClassReader(is);
    ClassWriter cw = new ClassWriter(compute);
    ClassAdapter ca = new ClassAdapter(cw);
    cr.accept(ca, skipDebug);
    return cw.toByteArray();
  }
View Full Code Here

  }

  byte[] counterAdaptClass (final InputStream is, final String name)
    throws Exception
  {
    ClassReader cr = new ClassReader(is);
    ClassWriter cw = new ClassWriter(false);
    ClassAdapter ca = new CounterClassAdapter(cw);
    cr.accept(ca, false);
    return cw.toByteArray();
  }
View Full Code Here

public class Attributes extends ClassLoader {

  public static void main (final String args[]) throws Exception {
    // loads the original class and adapts it
    ClassReader cr = new ClassReader("CommentAttribute");
    ClassWriter cw = new ClassWriter(false);
    ClassVisitor cv = new AddCommentClassAdapter(cw);
    cr.accept(cv, new Attribute[] { new CommentAttribute("") }, false);
    byte[] b = cw.toByteArray();

    // stores the adapted class on disk
    FileOutputStream fos = new FileOutputStream("CommentAttribute.class.new");
    fos.write(b);
    fos.close();

    // "disassembles" the adapted class
    cr = new ClassReader(b);
    cv = new TraceClassVisitor(null, new PrintWriter(System.out));
    cr.accept(cv, new Attribute[] { new CommentAttribute("") }, false);
  }
View Full Code Here

        ZipEntry e = (ZipEntry)entries.nextElement();
        String s = e.getName();
        if (s.endsWith(".class")) {
          s = s.substring(0, s.length() - 6).replace('/', '.');
          InputStream is = zip.getInputStream(e);
          new ClassReader(is).accept(new EmptyClassVisitor(), false);
        }
      }
      t = System.currentTimeMillis() - t;
      System.out.println("Time to deserialize " + n + " classes = " + t + " ms");
    }
   
    for (int i = 0; i < 5; ++i) {
      long t = System.currentTimeMillis();
      Enumeration entries = zip.entries();
      while (entries.hasMoreElements()) {
        ZipEntry e = (ZipEntry)entries.nextElement();
        String s = e.getName();
        if (s.endsWith(".class")) {
          s = s.substring(0, s.length() - 6).replace('/', '.');
          InputStream is = zip.getInputStream(e);
          ClassWriter cw = new ClassWriter(false);
          new ClassReader(is).accept(cw, false);
          cw.toByteArray();
        }
      }
      t = System.currentTimeMillis() - t;
      System.out.println("Time to deserialize and reserialize " + n + " classes = " + t + " ms");
View Full Code Here

TOP

Related Classes of org.objectweb.asm.ClassReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.