1 19 package gcc.rmi; 20 21 import gcc.*; 22 import gcc.properties.*; 23 import gcc.util.*; 24 25 public class RmiTrace 26 { 27 public static final boolean ENABLED = true; 28 public static final boolean CONNECT = true; 29 30 public RmiTrace() 31 { 32 } 33 34 public static void receive(String host, byte[] data) 35 { 36 dump(formatReceiveHeader(host), data); 37 } 38 39 public static void send(String host, byte[] data) 40 { 41 dump(formatSendHeader(host), data); 42 } 43 44 public static void dump(String header, byte[] data) 45 { 46 traceRmiHeader(header); 47 StringBuffer dataBuffer = new StringBuffer(44); 48 StringBuffer textBuffer = new StringBuffer(20); 49 for (int i = 0; i < data.length; i++) 50 { 51 int d = (data[i] + 0x100) & 0xff; 52 String h = StringUtil.padLeft(Integer.toHexString(d).toUpperCase(), '0', 2); 53 dataBuffer.append(h); 54 if (i % 4 == 3 && i % 20 != 19) 55 { 56 dataBuffer.append(' '); 57 } 58 char c = (char)d; 59 if (c < 32 || c > 127) 60 { 61 c = '.'; 62 } 63 textBuffer.append(c); 64 if (i % 20 == 19) 65 { 66 traceRmi(StringUtil.padRight(dataBuffer.toString(), ' ', 44), textBuffer.toString()); 67 dataBuffer.setLength(0); 68 textBuffer.setLength(0); 69 } 70 } 71 if (dataBuffer.length() != 0) 72 { 73 traceRmi(StringUtil.padRight(dataBuffer.toString(), ' ', 44), textBuffer.toString()); 74 } 75 } 76 77 79 protected static String formatReceiveHeader(String host) 80 { 81 String msg; 82 msg = "RmiTrace.formatReceiveHeader(): host: " + host; 83 return msg; 84 } 85 86 protected static String formatSendHeader(String host) 87 { 88 String msg; 89 msg = "RmiTrace.formatSendHeader(): host: " + host; 90 return msg; 91 } 92 93 94 96 public static void traceConnect(String endpoint) 97 { 98 System.out.println( "RmiTrace.traceConnect(): endpoint: " + endpoint ); 99 } 100 101 public static void traceDisconnect(String endpoint) 102 { 103 System.out.println( "RmiTrace.traceDisconnect(): endpoint: " + endpoint ); 104 } 105 106 protected static void traceRmiHeader(String header) 107 { 108 System.out.println( "RmiTrace.traceRmiHeader(): header: " + header ); 109 } 110 111 protected static void traceRmi(String data, String text) 112 { 113 System.out.println( "RmiTrace.traceRmi(): data: " + data + ", text: " + text ); 114 } 115 116 } 117 | Popular Tags |