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 public class BufferedWriterAdapter extends ClassAdapter implements Opcodes { 13 14 public BufferedWriterAdapter(ClassVisitor cv) { 15 super(cv); 16 } 17 18 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 19 MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 20 if ("write".equals(name) && "(Ljava/lang/String;II)V".equals(desc)) { return new WriteStringAdatper(mv); } 21 return mv; 22 } 23 24 private static class WriteStringAdatper extends MethodAdapter { 25 26 public WriteStringAdatper(MethodVisitor mv) { 27 super(mv); 28 } 29 30 public void visitMethodInsn(int opcode, String owner, String name, String desc) { 31 if ((INVOKEVIRTUAL == opcode) && ("java/lang/String".equals(owner) && "getChars".equals(name))) { 32 super.visitMethodInsn(opcode, owner, "getCharsFast", desc); 33 } else { 34 super.visitMethodInsn(opcode, owner, name, desc); 35 } 36 } 37 38 } 39 40 } 41 | Popular Tags |