1 4 package com.tc.object.bytecode; 5 6 import com.tc.asm.ClassAdapter; 7 import com.tc.asm.ClassVisitor; 8 import com.tc.asm.MethodAdapter; 9 import com.tc.asm.MethodVisitor; 10 import com.tc.asm.Opcodes; 11 12 import java.lang.reflect.Modifier ; 13 14 public class DataOutputStreamAdapter extends ClassAdapter implements Opcodes { 15 16 public DataOutputStreamAdapter(ClassVisitor cv) { 17 super(cv); 18 } 19 20 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 21 MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 22 if (Modifier.isStatic(access) && "writeUTF".equals(name) 23 && "(Ljava/lang/String;Ljava/io/DataOutput;)I".equals(desc)) { return new WriteUTFAdatper(mv); } 24 return mv; 25 } 26 27 private static class WriteUTFAdatper extends MethodAdapter { 28 29 public WriteUTFAdatper(MethodVisitor mv) { 30 super(mv); 31 } 32 33 public void visitMethodInsn(int opcode, String owner, String name, String desc) { 34 if ((INVOKEVIRTUAL == opcode) && ("java/lang/String".equals(owner) && "getChars".equals(name))) { 35 super.visitMethodInsn(opcode, owner, "getCharsFast", desc); 36 } else { 37 super.visitMethodInsn(opcode, owner, name, desc); 38 } 39 } 40 41 } 42 43 } 44 | Popular Tags |