Package org.ow2.easybeans.asm

Examples of org.ow2.easybeans.asm.ClassWriter.toByteArray()


        ClassReader cr = new ClassReader(is);
        ClassWriter cw = new ClassWriter(0);
        ClassVisitor cv = new TraceClassVisitor(cw,
                new PrintWriter(new CharArrayWriter()));
        cr.accept(cv, new Attribute[] { new Comment(), new CodeComment() }, 0);
        assertEquals(cr, new ClassReader(cw.toByteArray()));
    }
}
View Full Code Here


        nativeMethod(cw);
        clinitMethod(cw);

        cw.visitEnd();

        return cw.toByteArray();
    }

    private void constInsns(final ClassWriter cw) {
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC,
                "constInsns",
View Full Code Here

    @Override
    public void test() throws Exception {
        ClassReader cr = new ClassReader(is);
        ClassWriter cw = new ClassWriter(0);
        cr.accept(new CheckClassAdapter(cw), 0);
        assertEquals(cr, new ClassReader(cw.toByteArray()));
    }
}
View Full Code Here

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

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

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

        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 value of this
View Full Code Here

            @Override
            public Class<?> loadClass(final String name)
                    throws ClassNotFoundException
            {
                if (name.equals(n)) {
                    byte[] b = cw.toByteArray();
                    return defineClass(name, b, 0, b.length);
                }
                return super.loadClass(name);
            }
        }.loadClass(n);
View Full Code Here

        // variables
        mw.visitMaxs(2, 2);
        mw.visitEnd();

        // gets the bytecode of the Example class, and loads it dynamically
        byte[] code = cw.toByteArray();

        FileOutputStream fos = new FileOutputStream("Example.class");
        fos.write(code);
        fos.close();
View Full Code Here

        mg.returnValue();
        mg.endMethod();

        cw.visitEnd();

        code = cw.toByteArray();
        loader = new Helloworld();
        exampleClass = loader.defineClass("Example", code, 0, code.length);

        // uses the dynamically generated class to print 'Helloworld'
        exampleClass.getMethods()[0].invoke(null, new Object[] { null });
View Full Code Here

        }

        r.close();

        FileOutputStream os = new FileOutputStream(className + ".class");
        os.write(cw.toByteArray());
        os.flush();
        os.close();
    }

}
View Full Code Here

                    ClassWriter.COMPUTE_MAXS);
            return new ASMContentHandler(cw) {
                @Override
                public void endDocument() throws SAXException {
                    try {
                        os.write(cw.toByteArray());
                    } catch(IOException e) {
                        throw new SAXException(e);
                    }
                }
            };
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.