mercredi 19 août 2015

Class creating by copying doesnt work

I am following the exmaple in the ASM 4.0 manual, in the section which explains the visitor there is an exmaple of copying the class using a code similar to this:

    InputStream in=ASMHelloWorld.class.getResourceAsStream("Test.class");
    ClassWriter cw = new ClassWriter(0);
    ClassReader cr = new ClassReader(in);
    cr.accept(cw, 0);
    byte[] b2 = cw.toByteArray(); // b2 represents the same class as b1

The difference is that in the book they define the input data as byte array but I dont know how to read a class as byte array, instead I used an example I found online to read the class as InputStream.

I save the class using the following code:

    DataOutputStream os = new DataOutputStream(new FileOutputStream("Test2.class"));
    os.write(b2);
    os.flush();
    os.close();

The thing is that when I try to run Test2 I get the following error:

Error: Could not find or load main class Test2

The size of Test.class and Test2.class are the same





Aucun commentaire:

Enregistrer un commentaire