KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > BufferedWriterAdapter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc name, String JavaDoc desc, String JavaDoc signature, String JavaDoc[] 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 JavaDoc owner, String JavaDoc name, String JavaDoc 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