KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.lang.reflect.Modifier JavaDoc;
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 JavaDoc name, String JavaDoc desc, String JavaDoc signature, String JavaDoc[] 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 JavaDoc owner, String JavaDoc name, String JavaDoc 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