01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.bytecode;
05:
06: import com.tc.asm.ClassAdapter;
07: import com.tc.asm.ClassVisitor;
08: import com.tc.asm.MethodAdapter;
09: import com.tc.asm.MethodVisitor;
10: import com.tc.asm.Opcodes;
11:
12: public class BufferedWriterAdapter extends ClassAdapter implements
13: Opcodes {
14:
15: public BufferedWriterAdapter(ClassVisitor cv) {
16: super (cv);
17: }
18:
19: public MethodVisitor visitMethod(int access, String name,
20: String desc, String signature, String[] exceptions) {
21: MethodVisitor mv = super .visitMethod(access, name, desc,
22: signature, exceptions);
23: if ("write".equals(name)
24: && "(Ljava/lang/String;II)V".equals(desc)) {
25: return new WriteStringAdatper(mv);
26: }
27: return mv;
28: }
29:
30: private static class WriteStringAdatper extends MethodAdapter {
31:
32: public WriteStringAdatper(MethodVisitor mv) {
33: super (mv);
34: }
35:
36: public void visitMethodInsn(int opcode, String owner,
37: String name, String desc) {
38: if ((INVOKEVIRTUAL == opcode)
39: && ("java/lang/String".equals(owner) && "getChars"
40: .equals(name))) {
41: super .visitMethodInsn(opcode, owner, "getCharsFast",
42: desc);
43: } else {
44: super.visitMethodInsn(opcode, owner, name, desc);
45: }
46: }
47:
48: }
49:
50: }
|