Java 类sun.misc.ProxyGenerator 实例源码

项目:My-MVP    文件:MainClass.java   
private static void createProxyClassFile() {
    String name = "ProxySubject";
    byte[] data = ProxyGenerator.generateProxyClass(name, new Class[]{Subject.class});
    try {
        FileOutputStream out = new FileOutputStream(name + ".class");
        out.write(data);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:JavaDesignPattern    文件:JDKDynamicProxyClient.java   
public static void main(String[] args) throws IOException {
  InvocationHandler handler = new SubjectProxyHandler(ConcreteSubject.class);
  ISubject subject =
      (ISubject) Proxy.newProxyInstance(JDKDynamicProxyClient.class.getClassLoader(),
          new Class[] {ISubject.class}, handler);
  subject.action();
  LOG.info("Proxy class name {}", subject.getClass().getName());
  byte[] classFile = ProxyGenerator.generateProxyClass("$Proxy18", ConcreteSubject.class.getInterfaces());  
  try(OutputStream outputStream = new FileOutputStream("$Proxy18.class")){
    IOUtils.write(classFile, outputStream);
  }
}
项目:KeepTry    文件:SaveDynamicProxyClass.java   
public static void main(String[] args) throws IOException {
    byte[] classFile = ProxyGenerator.generateProxyClass("TestProxyGen", Worker.class.getInterfaces());
    File file = new File("./DenamixProxyGen.class");
    file.setWritable(true);
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(classFile);
    fos.flush();
    fos.close();
}
项目:proxyhotswap    文件:JavaProxyTransformer.java   
@Override
protected byte[] getNewByteCode(ClassLoader loader, String className, Class<?> classBeingRedefined) {
    return ProxyGenerator.generateProxyClass(className, classBeingRedefined.getInterfaces());
}