当前位置: 首页 > news >正文

做论坛网站需要多少钱南昌seo站外优化

做论坛网站需要多少钱,南昌seo站外优化,网站收录怎么弄,温州自适应网站建设什么是ASM树API#xff1a; ASM树API是ASM的一部分#xff0c;可让您创建/修改内存中的类。 该类被视为信息树。 像整个类一样#xff0c;它是ClassNode的实例#xff0c;其中包含FieldNode对象列表#xff0c;MethodNode对象列表等。本文假设读者已经在这里阅读了第一部分… 什么是ASM树API ASM树API是ASM的一部分可让您创建/修改内存中的类。 该类被视为信息树。 像整个类一样它是ClassNode的实例其中包含FieldNode对象列表MethodNode对象列表等。本文假设读者已经在这里阅读了第一部分。 通过树API的简单类让我们使用树API创建我们的第一类。 同样我将直接进入一个代码示例因为没有什么比代码示例更好。 生成的类具有打印“ Hello World”的主要方法。 TreeAPIDemo.java package com.geekyarticles.asm;import java.io.DataOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream;import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode;public class TreeAPIDemo {public static void main(String [] args) throws Exception{ClassNode classNodenew ClassNode(4);//4 is just the API version number//These properties of the classNode must be setclassNode.versionOpcodes.V1_6;//The generated class will only run on JRE 1.6 or aboveclassNode.accessOpcodes.ACC_PUBLIC;classNode.signatureLcom/geekyarticles/asm/Generated;;classNode.namecom/geekyarticles/asm/Generated;classNode.superNamejava/lang/Object;//Create a methodMethodNode mainMethodnew MethodNode(4,Opcodes.ACC_PUBLIC|Opcodes.ACC_STATIC,main, ([Ljava/lang/String;)V,null, null);mainMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, java/lang/System, out, Ljava/io/PrintStream;));mainMethod.instructions.add(new LdcInsnNode(Hello World!));mainMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, java/io/PrintStream, println, (Ljava/lang/String;)V));mainMethod.instructions.add(new InsnNode(Opcodes.RETURN));//Add the method to the classNodeclassNode.methods.add(mainMethod);//Write the classClassWriter cwnew ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES);classNode.accept(cw);//Dump the class in a fileFile outDirnew File(out/com/geekyarticles/asm);outDir.mkdirs();DataOutputStream doutnew DataOutputStream(new FileOutputStream(new File(outDir,Generated.class)));dout.write(cw.toByteArray());dout.flush();dout.close();} } 如您所见代码非常简单。 与BCEL相比它的主要优点是与BCEL不同ASM不需要您将每个常量显式添加到常量池中。 相反ASM会照顾常量池本身。 读取类文件 ClassNode是ClassVisitor。 因此读取用于树API的类就像创建ClassReader对象并使用它读取类文件一样简单同时将ClassNode对象作为其accept方法传递给参数。 完成此操作后将通过类中存在的所有信息完全初始化传递的ClassNode。 在下面的示例中我们将打印类中的所有方法。 TreeAPIClassReaderDemo.java package com.geekyarticles.asm;import java.io.FileInputStream; import java.io.InputStream;import org.objectweb.asm.ClassReader; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode;public class TreeAPIClassReaderDemo {public static void main(String[] args) throws Exception{InputStream innew FileInputStream(out/com/geekyarticles/asm/Generated.class);ClassReader crnew ClassReader(in);ClassNode classNodenew ClassNode();//ClassNode is a ClassVisitorcr.accept(classNode, 0);//Lets move through all the methodsfor(MethodNode methodNodeclassNode.methods){System.out.println(methodNode.name methodNode.desc);}}} 修改类文件修改类文件是上述两个过程的组合。 我们首先以通常的方式读取该类对数据进行必要的更改然后将其写回到文件中。 以下程序实现了一些日志代码的自动注入。 当前我们的Logger类仅打印到标准输出。 Loggable注释的每个方法在开始和返回时都将被记录。 在此我们不记录throw-exception。 但是也可以通过检查操作码ATHROW以相同的方式实现。 LoggingInsertion.java package com.geekyarticles.asm;import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Iterator;import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode;public class LoggingInsertion {public static void main(String[] args) throws Exception{InputStream inLoggingInsertion.class.getResourceAsStream(/com/geekyarticles/asm/LoggingTest.class);ClassReader crnew ClassReader(in);ClassNode classNodenew ClassNode();cr.accept(classNode, 0);//Lets move through all the methodsfor(MethodNode methodNodeclassNode.methods){System.out.println(methodNode.name methodNode.desc);boolean hasAnnotationfalse;if(methodNode.visibleAnnotations!null){for(AnnotationNode annotationNodemethodNode.visibleAnnotations){if(annotationNode.desc.equals(Lcom/geekyarticles/asm/Loggable;)){hasAnnotationtrue;break;}}}if(hasAnnotation){//Lets insert the begin loggerInsnList beginListnew InsnList();beginList.add(new LdcInsnNode(methodNode.name));beginList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, com/geekyarticles/asm/Logger, logMethodStart, (Ljava/lang/String;)V));IteratorAbstractInsnNode insnNodesmethodNode.instructions.iterator();while(insnNodes.hasNext()){System.out.println(insnNodes.next().getOpcode());}methodNode.instructions.insert(beginList);System.out.println(methodNode.instructions);//A method can have multiple places for return//All of them must be handled.insnNodesmethodNode.instructions.iterator();while(insnNodes.hasNext()){AbstractInsnNode insninsnNodes.next();System.out.println(insn.getOpcode());if(insn.getOpcode()Opcodes.IRETURN||insn.getOpcode()Opcodes.RETURN||insn.getOpcode()Opcodes.ARETURN||insn.getOpcode()Opcodes.LRETURN||insn.getOpcode()Opcodes.DRETURN){InsnList endListnew InsnList();endList.add(new LdcInsnNode(methodNode.name));endList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, com/geekyarticles/asm/Logger, logMethodReturn, (Ljava/lang/String;)V));methodNode.instructions.insertBefore(insn, endList);}}}}//We are done now. so dump the classClassWriter cwnew ClassWriter(ClassWriter.COMPUTE_MAXS|ClassWriter.COMPUTE_FRAMES);classNode.accept(cw);File outDirnew File(out/com/geekyarticles/asm);outDir.mkdirs();DataOutputStream doutnew DataOutputStream(new FileOutputStream(new File(outDir,LoggingTest.class)));dout.write(cw.toByteArray());dout.flush();dout.close();}} LoggingTest.java package com.geekyarticles.asm;public class LoggingTest {public static void run1(){System.out.println(run 1);}Loggablepublic static void run2(){System.out.println(run 2);}Loggablepublic static void main(String [] args){run1();run2();} } 记录器 package com.geekyarticles.asm;public class Logger {public static void logMethodStart(String methodName){System.out.println(Starting method: methodName);}public static void logMethodReturn(String methodName){System.out.println(Ending method: methodName);} } Loggable.java package com.geekyarticles.asm;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Target(ElementType.METHOD) Retention(RetentionPolicy.RUNTIME) public interface Loggable {} 如果运行此程序则生成的文件将依赖于Logger类。 手动将Logger类复制到out目录中的正确软件包。 如果运行生成的类它是LoggingTest类的修改版本则将输出以下内容。 bash-4.1$ java com.geekyarticles.asm.LoggingTest Starting method: main run 1 Starting method: run2 run 2 Ending method: run2 Ending method: main 请注意与普通列表不同在迭代InsnList对象时可以对其进行修改。 任何更改都会立即反映出来。 因此如果在当前位置之后插入了一些指令则也将对其进行迭代。 参考 使用ASM 4处理Java类文件–第二部分 JCG合作伙伴提供的 Tree API   极客文章博客上的Debasish Ray Chawdhuri。 翻译自: https://www.javacodegeeks.com/2012/02/manipulating-java-class-files-with-asm_22.html
http://www.sadfv.cn/news/87186/

相关文章:

  • 网站建设怎样接业务查询网站相关网址
  • 具有品牌的上海网站建设如何制作大量网页
  • 网站建设公司名片网站的建设及推广
  • 网站后台程序开发教程wordpress导出出错
  • 企业网站空间在哪里企业标志logo设计图片
  • 网站建设试题以及答案网站权重数据包
  • 网站风格评价标准品购买网站
  • linux 网站建设模板网站项目经费预算
  • 网站宣传内容鲜花网站模板下载
  • wap建设网站福田企业网站推广哪个好
  • 西安网站价格wordpress导航主题模板下载地址
  • 大连网站建设方案案例网站备案知识
  • 可以在线编程的网站成都高端网站建设公司
  • 爱网站关键词挖掘工具游戏创作平台
  • seo怎么做网站的tdk在哪学习建网站
  • 网站推广策略有哪些wordpress4.5.3漏洞
  • 手机免费制作网站模板网站用户体验优化方案
  • 邵阳邵东网站建设免费完整视频播放器哔哩哔哩
  • 网站建设审批表网站留言板 html
  • 网站开发源代码什么意思全国网络维护的公司排名
  • 在哪个网站去租地方做收废站厦门网站建设公司哪个好
  • 广州婚恋网站排名重庆制作网页设计
  • 怎样免费自己做网站视频永久免费可联网的进销存软件
  • 做外贸没有企业网站阿里巴巴运营要学多久
  • 学科网站建设王也个人资料
  • 自助服务系统网站贵州建网站报价
  • 淮南先锋网谷歌seo运营
  • 注册网站域名平台做网站的复式照片
  • 提供微网站建设网站建设做微营销
  • 什么网站做的最好wordpress 调用最新文章