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: import java.lang.reflect.Modifier;
13:
14: public class DataOutputStreamAdapter extends ClassAdapter implements
15: Opcodes {
16:
17: public DataOutputStreamAdapter(ClassVisitor cv) {
18: super (cv);
19: }
20:
21: public MethodVisitor visitMethod(int access, String name,
22: String desc, String signature, String[] exceptions) {
23: MethodVisitor mv = super .visitMethod(access, name, desc,
24: signature, exceptions);
25: if (Modifier.isStatic(access)
26: && "writeUTF".equals(name)
27: && "(Ljava/lang/String;Ljava/io/DataOutput;)I"
28: .equals(desc)) {
29: return new WriteUTFAdatper(mv);
30: }
31: return mv;
32: }
33:
34: private static class WriteUTFAdatper extends MethodAdapter {
35:
36: public WriteUTFAdatper(MethodVisitor mv) {
37: super (mv);
38: }
39:
40: public void visitMethodInsn(int opcode, String owner,
41: String name, String desc) {
42: if ((INVOKEVIRTUAL == opcode)
43: && ("java/lang/String".equals(owner) && "getChars"
44: .equals(name))) {
45: super .visitMethodInsn(opcode, owner, "getCharsFast",
46: desc);
47: } else {
48: super.visitMethodInsn(opcode, owner, name, desc);
49: }
50: }
51:
52: }
53:
54: }
|