Package org.objectweb.asm

Examples of org.objectweb.asm.ClassWriter.toByteArray()


  {
    ClassReader cr = new ClassReader(is);
    ClassWriter cw = new ClassWriter(compute);
    ClassAdapter ca = new ClassAdapter(cw);
    cr.accept(ca, skipDebug);
    return cw.toByteArray();
  }

  byte[] counterAdaptClass (final InputStream is, final String name)
    throws Exception
  {
View Full Code Here


  {
    ClassReader cr = new ClassReader(is);
    ClassWriter cw = new ClassWriter(false);
    ClassAdapter ca = new CounterClassAdapter(cw);
    cr.accept(ca, false);
    return cw.toByteArray();
  }

  static class CounterClassAdapter extends ClassAdapter implements Constants {

    private String owner;
View Full Code Here

    // 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();
View Full Code Here

        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

    try {
      ClassReader cr = new ClassReader(is);
      ClassWriter cw = new ClassWriter(false);
      ClassVisitor cv = new TraceFieldClassAdapter(cw);
      cr.accept(cv, false);
      b = cw.toByteArray();
    } catch (Exception e) {
      throw new ClassNotFoundException(name, e);
    }

    // optional: stores the adapted class on disk
View Full Code Here

    compile(mw);
    mw.visitInsn(IRETURN);
    // max stack and max locals automatically computed
    mw.visitMaxs(0, 0);

    return cw.toByteArray();
  }

  /*
   * Compile this expression. This method must append to the given code
   * writer the byte code that evaluates and pushes on the stack the
View Full Code Here

    byte[] classData = getCode( new URL( className).openStream());
   
    ClassReader cr = new ClassReader( classData);
    ClassWriter cw = new ClassWriter( false, false);
    cr.accept(cw, Attributes.getDefaultAttributes(), false);
    byte[] newData = cw.toByteArray();

    try {
    assertTrue( Arrays.equals( classData, newData));
     
    } catch( Throwable ex) {
View Full Code Here

      }
      FileOutputStream classOutStream = null;
      try {
        //write out the new bytes of the class file
        classOutStream = new FileOutputStream(arg);
        if (writer != null) classOutStream.write(writer.toByteArray());
      } finally {
        //close the OutputStream if it is still around
        if (classOutStream != null) classOutStream.close();
      }
    }
View Full Code Here

                               new WovenProxyAdapter(cv, cReader.getClassName(), loader));
   
    // If we are Java 1.6 + then we need to skip frames as they will be recomputed
    cReader.accept(weavingAdapter, AbstractWovenProxyAdapter.IS_AT_LEAST_JAVA_6 ? ClassReader.SKIP_FRAMES : 0);
   
    return cWriter.toByteArray();
  }
}
View Full Code Here

            ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS/* | ClassWriter.COMPUTE_FRAMES*/);
            try {
                ClassVisitor ci = (ClassVisitor) INSTRUMENTER_CONSTRUCTOR.newInstance(projectData, cw, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
                cr.accept(ci, 0);
                if (((Boolean) IS_INSTRUMENTED_METHOD.invoke(ci)).booleanValue()) {
                    return cw.toByteArray();
                }
            } catch (Throwable t) {
                throw (IOException) new IOException(t.getMessage()).initCause(t);
            }
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.