1 21 package org.apache.derby.impl.drda; 22 23 public class DssTrace 28 { 29 private static final String LIST_SEPARATOR = " # "; 34 35 private static final String NULL_VALUE = "null"; 37 38 private static final char asciiChar [] = { 42 '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', ' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/', '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?', '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', 'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_', '`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', 'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.' }; 60 61 62 private static CodePointNameTable codePointNameTable = null; 70 71 private static final String colPosHeader = 73 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 0123456789ABCDEF"; 74 75 private static final char ebcdicChar[] = { 79 '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', ' ','.','.','.','.','.','.','.','.','.','.','.','<','(','+','|', '&','.','.','.','.','.','.','.','.','.','!','$','*',')',';','.', '-','/','.','.','.','.','.','.','.','.','|',',','%','_','>','?', '.','.','.','.','.','.','.','.','.','`',':','#','@','\'','=','"', '.','a','b','c','d','e','f','g','h','i','.','.','.','.','.','.', '.','j','k','l','m','n','o','p','q','r','.','.','.','.','.','.', '.','~','s','t','u','v','w','x','y','z','.','.','.','.','.','.', '.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.', '{','A','B','C','D','E','F','G','H','I','.','.','.','.','.','.', '}','J','K','L','M','N','O','P','Q','R','.','.','.','.','.','.', '\\','.','S','T','U','V','W','X','Y','Z','.','.','.','.','.','.', '0','1','2','3','4','5','6','7','8','9','.','.','.','.','.','.' }; 97 98 99 private static final char hexDigit [] = { 101 '0','1','2','3','4','5','6','7', 102 '8','9','A','B','C','D','E','F' 103 }; 104 105 106 private java.io.PrintWriter comBufferWriter = null; 108 109 110 private static final String receiveHeader = 113 " RECEIVE BUFFER: (ASCII) (EBCDIC)"; 114 115 116 private static final String sendHeader = 119 " SEND BUFFER: (ASCII) (EBCDIC)"; 120 121 122 private static final char spaceChar = ' '; 124 125 126 private boolean comBufferTraceOn = false; 130 131 132 private Boolean comBufferSync = new Boolean (true); 139 140 141 private static final char zeroChar = '0'; 143 144 protected static final int TYPE_TRACE_RECEIVE = 2; 147 148 protected static final int TYPE_TRACE_SEND = 1; 151 152 protected boolean isComBufferTraceOn() 155 { 156 return comBufferTraceOn; 158 } 159 160 protected void startComBufferTrace (String fileName) 164 { 165 synchronized (comBufferSync) { 166 try { 167 if (comBufferTraceOn == false) { 169 comBufferWriter = new java.io.PrintWriter (new java.io.BufferedWriter (new java.io.FileWriter (fileName), 4096)); 171 comBufferTraceOn = true; 173 if (DssTrace.codePointNameTable == null) { 180 codePointNameTable = new CodePointNameTable(); 181 } 182 } 183 } 184 catch (java.io.IOException e) { 185 } 187 } 188 } 189 190 protected void stopComBufferTrace () 194 { 195 synchronized (comBufferSync) { 196 if (comBufferTraceOn == true) { 198 comBufferTraceOn = false; 200 comBufferWriter.flush(); 202 comBufferWriter.close(); 203 } 204 } 205 } 206 207 protected void writeComBufferData (byte[] buff, 213 int offset, 214 int len, 215 int type, 216 String className, 217 String methodName, 218 int trcPt) 219 { 220 222 synchronized (comBufferSync) { 225 226 if (comBufferTraceOn) { 228 229 java.util.Calendar time = java.util.Calendar.getInstance(); 232 233 comBufferWriter.println (" (" + 235 time.get (java.util.Calendar.YEAR) + 236 "." + 237 (time.get (java.util.Calendar.MONTH) + 1) + 238 "." + 239 time.get (java.util.Calendar.DAY_OF_MONTH) + 240 " " + 241 time.get (java.util.Calendar.HOUR_OF_DAY) + 242 ":" + 243 time.get (java.util.Calendar.MINUTE) + 244 ":" + 245 time.get (java.util.Calendar.SECOND) + 246 ") " + 247 className + 248 " " + 249 methodName + 250 " " + 251 Thread.currentThread().getName() + 252 " " + 253 trcPt); 254 255 comBufferWriter.println(); 257 258 if (len != 0) { 260 String codePointName = null; 261 if (len >= 10) { 263 int codePoint = getCodePoint (buff, offset+8); 265 codePointName = codePointNameTable.lookup (codePoint); 266 } 267 268 if (codePointName == null) { 269 comBufferWriter.println (getHeader (type)); 272 } 273 else { 274 printHeaderWithCodePointName (codePointName, type); 276 } 277 278 comBufferWriter.println (colPosHeader); 280 281 char trcDump[] = new char[77]; 284 285 short bCounter = 7; 287 short aCounter = 43; 288 short eCounter = 61; 289 290 trcDump[0] = DssTrace.zeroChar; 293 trcDump[1] = DssTrace.zeroChar; 294 trcDump[2] = DssTrace.zeroChar; 295 trcDump[3] = DssTrace.zeroChar; 296 297 int lineCounter = 0x10; 299 300 for (int j = 4; j < 77; j++) { 304 trcDump[j] = DssTrace.spaceChar; 305 } 306 307 int i = 0; 309 310 do { 311 int num = (buff[offset] < 0)? buff[offset] + 256 : buff[offset]; offset++; 315 i++; 316 trcDump[bCounter++] = DssTrace.hexDigit[((num >>> 4) & 0xf)]; 318 trcDump[bCounter++] = DssTrace.hexDigit[(num & 0xf)]; 319 320 trcDump[aCounter++] = DssTrace.asciiChar[num]; 322 trcDump[eCounter++] = DssTrace.ebcdicChar[num]; 323 324 if (((i%8) == 0)) { 325 if (((i%16) == 0)) { 326 comBufferWriter.println (trcDump); 328 if (i != len) { 329 if ((len - i) < 16) { 331 for (int j = 0; j < trcDump.length; j++) { 335 trcDump[j] = DssTrace.spaceChar; 336 } 337 } 338 bCounter = 0; 340 aCounter = 43; 341 eCounter = 61; 342 if (lineCounter == 0xfff0) { 344 lineCounter = 0; 345 } 346 trcDump[bCounter++] = DssTrace.hexDigit[((lineCounter >>> 12) & 0xf)]; 348 trcDump[bCounter++] = DssTrace.hexDigit[((lineCounter >>> 8) & 0xf)]; 349 trcDump[bCounter++] = DssTrace.hexDigit[((lineCounter >>> 4) & 0xf)]; 350 trcDump[bCounter++] = DssTrace.hexDigit[(lineCounter & 0xf)]; 351 bCounter += 3; 352 lineCounter += 0x10; 354 } 355 } 356 else { 357 bCounter += 2; 360 } 361 } 362 } while (i < len); 364 365 if (len % 16 != 0) { 367 comBufferWriter.println (trcDump); 368 } 369 comBufferWriter.println(); 370 comBufferWriter.println(); 371 } 372 comBufferWriter.flush(); 374 } 375 } 376 } 377 378 private static int getCodePoint (byte[] buff, int offset) 380 { 381 return ((buff[offset++] & 0xff) << 8) + 382 ((buff[offset] & 0xff) << 0); 383 } 384 385 private static String getHeader (int type) 386 { 387 switch (type) { 388 case DssTrace.TYPE_TRACE_SEND: 389 return DssTrace.sendHeader; 390 case DssTrace.TYPE_TRACE_RECEIVE: 391 return DssTrace.receiveHeader; 392 default: 393 return null; 395 } 396 } 397 398 private static int getStartPosition (int type) 399 { 400 switch (type) { 401 case DssTrace.TYPE_TRACE_SEND: 402 return 20; case DssTrace.TYPE_TRACE_RECEIVE: 404 return 23; default: 406 return 0; 408 } 409 } 410 411 private void printHeaderWithCodePointName (String codePointName, int type) 412 { 413 char headerArray[] = DssTrace.getHeader(type).toCharArray(); 416 417 int replaceLen = (codePointName.length() < 17) ? codePointName.length() : 16; 420 421 int offset = getStartPosition (type); 422 for (int i = 0; i < replaceLen; i++) { 423 headerArray[offset++] = codePointName.charAt (i); } 425 comBufferWriter.println (headerArray); 426 } 427 428 } 429 | Popular Tags |