private byte[] generateClassFile(){
  addProxyMethod(hashCodeMethod,Object.class);
  addProxyMethod(equalsMethod,Object.class);
  addProxyMethod(toStringMethod,Object.class);
  for (  Class<?> intf : interfaces) {
    for (    Method m : intf.getMethods()) {
      addProxyMethod(m,intf);
    }
  }
  for (  List<ProxyMethod> sigmethods : proxyMethods.values()) {
    checkReturnTypes(sigmethods);
  }
  try {
    methods.add(generateConstructor());
    for (    List<ProxyMethod> sigmethods : proxyMethods.values()) {
      for (      ProxyMethod pm : sigmethods) {
        fields.add(new FieldInfo(pm.methodFieldName,"Ljava/lang/reflect/Method;",ACC_PRIVATE | ACC_STATIC));
        methods.add(pm.generateMethod());
      }
    }
    methods.add(generateStaticInitializer());
  }
 catch (  IOException e) {
    throw new InternalError("unexpected I/O Exception",e);
  }
  if (methods.size() > 65535) {
    throw new IllegalArgumentException("method limit exceeded");
  }
  if (fields.size() > 65535) {
    throw new IllegalArgumentException("field limit exceeded");
  }
  cp.getClass(dotToSlash(className));
  cp.getClass(superclassName);
  for (  Class<?> intf : interfaces) {
    cp.getClass(dotToSlash(intf.getName()));
  }
  cp.setReadOnly();
  ByteArrayOutputStream bout=new ByteArrayOutputStream();
  DataOutputStream dout=new DataOutputStream(bout);
  try {
    dout.writeInt(0xCAFEBABE);
    dout.writeShort(CLASSFILE_MINOR_VERSION);
    dout.writeShort(CLASSFILE_MAJOR_VERSION);
    cp.write(dout);
    dout.writeShort(accessFlags);
    dout.writeShort(cp.getClass(dotToSlash(className)));
    dout.writeShort(cp.getClass(superclassName));
    dout.writeShort(interfaces.length);
    for (    Class<?> intf : interfaces) {
      dout.writeShort(cp.getClass(dotToSlash(intf.getName())));
    }
    dout.writeShort(fields.size());
    for (    FieldInfo f : fields) {
      f.write(dout);
    }
    dout.writeShort(methods.size());
    for (    MethodInfo m : methods) {
      m.write(dout);
    }
    dout.writeShort(0);
  }
 catch (  IOException e) {
    throw new InternalError("unexpected I/O Exception",e);
  }
  return bout.toByteArray();
}

private byte [ ] generateClassFile ( ) { addProxyMethod ( hashCodeMethod , Object . class ) ; addProxyMethod ( equalsMethod , Object . class ) ; addProxyMethod ( toStringMethod , Object . class ) ; for ( Class < ? > intf : interfaces ) { for ( Method m : intf . getMethods ( ) ) { addProxyMethod ( m , intf ) ; } } for ( List < ProxyMethod > sigmethods : proxyMethods . values ( ) ) { checkReturnTypes ( sigmethods ) ; } try { methods . add ( generateConstructor ( ) ) ; for ( List < ProxyMethod > sigmethods : proxyMethods . values ( ) ) { for ( ProxyMethod pm : sigmethods ) { fields . add ( new FieldInfo ( pm . methodFieldName , "Ljava/lang/reflect/Method;" , ACC_PRIVATE | ACC_STATIC ) ) ; methods . add ( pm . generateMethod ( ) ) ; } } methods . add ( generateStaticInitializer ( ) ) ; } catch ( IOException e ) { throw new InternalError ( "unexpected I/O Exception" , e ) ; } if ( methods . size ( ) > 65535 ) { throw new IllegalArgumentException ( "method limit exceeded" ) ; } if ( fields . size ( ) > 65535 ) { throw new IllegalArgumentException ( "field limit exceeded" ) ; } cp . getClass ( dotToSlash ( className ) ) ; cp . getClass ( superclassName ) ; for ( Class < ? > intf : interfaces ) { cp . getClass ( dotToSlash ( intf . getName ( ) ) ) ; } cp . setReadOnly ( ) ; ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; DataOutputStream dout = new DataOutputStream ( bout ) ; try { dout . writeInt ( 0xCAFEBABE ) ; dout . writeShort ( CLASSFILE_MINOR_VERSION ) ; dout . writeShort ( CLASSFILE_MAJOR_VERSION ) ; cp . write ( dout ) ; dout . writeShort ( accessFlags ) ; dout . writeShort ( cp . getClass ( dotToSlash ( className ) ) ) ; dout . writeShort ( cp . getClass ( superclassName ) ) ; dout . writeShort ( interfaces . length ) ; for ( Class < ? > intf : interfaces ) { dout . writeShort ( cp . getClass ( dotToSlash ( intf . getName ( ) ) ) ) ; } dout . writeShort ( fields . size ( ) ) ; for ( FieldInfo f : fields ) { f . write ( dout ) ; } dout . writeShort ( methods . size ( ) ) ; for ( MethodInfo m : methods ) { m . write ( dout ) ; } dout . writeShort ( 0 ) ; } catch ( IOException e ) { throw new InternalError ( "unexpected I/O Exception" , e ) ; } return bout . toByteArray ( ) ; }
generate a class file for the proxy class . this method drives the class file generation process .
