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(); } }
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); } }
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(); }
@Override protected byte[] getNewByteCode(ClassLoader loader, String className, Class<?> classBeingRedefined) { return ProxyGenerator.generateProxyClass(className, classBeingRedefined.getInterfaces()); }