コード例 #1
0
ファイル: simple.java プロジェクト: brendandahl/j2me.js
  public static void main(String argv[]) throws jasError, IOException {

    // CodeAttr's contain the body of
    // a method.

    CodeAttr init = new CodeAttr();
    init.addInsn(new Insn(opc_aload_0));
    init.addInsn(new Insn(opc_invokenonvirtual, new MethodCP("java/lang/Object", "<init>", "()V")));
    init.addInsn(new Insn(opc_return));

    // ClassEnv's are used as a container
    // to hold all information about a class.

    ClassEnv nclass = new ClassEnv();
    nclass.setClass(new ClassCP("out"));
    nclass.setSuperClass(new ClassCP("java/lang/Object"));

    // Add the init code to the class.
    nclass.addMethod((short) ACC_PUBLIC, "<init>", "()V", init, null);

    // write it all out
    nclass.write(new DataOutputStream(new FileOutputStream("out.class")));
  }
コード例 #2
0
 /**
  * Writes the binary data for the class represented by this ClassFile object to the specified
  * output stream, using the Java Class File format. Throws either an IOException or a jasError if
  * something goes wrong.
  */
 public void write(OutputStream outp) throws IOException, jasError {
   class_env.setSource(source_name);
   class_env.write(new DataOutputStream(outp));
 }