本文整理汇总了Java中sun.misc.ProxyGenerator类的典型用法代码示例。如果您正苦于以下问题:Java ProxyGenerator类的具体用法?Java ProxyGenerator怎么用?Java ProxyGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProxyGenerator类属于sun.misc包,在下文中一共展示了ProxyGenerator类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import sun.misc.ProxyGenerator; //导入依赖的package包/类
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);
}
}
示例2: createProxyClassFile
import sun.misc.ProxyGenerator; //导入依赖的package包/类
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();
}
}
示例3: main
import sun.misc.ProxyGenerator; //导入依赖的package包/类
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();
}
示例4: getNewByteCode
import sun.misc.ProxyGenerator; //导入依赖的package包/类
@Override
protected byte[] getNewByteCode(ClassLoader loader, String className, Class<?> classBeingRedefined) {
return ProxyGenerator.generateProxyClass(className, classBeingRedefined.getInterfaces());
}