1 28 29 package com.caucho.es; 30 31 import com.caucho.java.LineMap; 32 import com.caucho.util.CharBuffer; 33 34 import java.io.CharArrayWriter ; 35 import java.io.IOException ; 36 import java.io.OutputStream ; 37 import java.io.PrintWriter ; 38 39 42 public class ESException extends Exception { 43 public ESException() {} 44 public ESException(String name) { super(name); } 45 public ESException(Throwable e) { super(e); } 46 47 public static void staticPrintESTrace(Exception e, OutputStream os) 48 { 49 CharArrayWriter writer = new CharArrayWriter (); 50 PrintWriter pw = new PrintWriter (writer); 51 52 e.printStackTrace(pw); 53 54 pw.close(); 55 char []array = writer.toCharArray(); 56 57 CharBuffer cb = filter(array); 58 59 if (os != null) { 60 byte []b = cb.toString().getBytes(); 61 62 try { 63 os.write(b, 0, b.length); 64 } catch (IOException e1) { 65 } 66 } else 67 System.out.println(cb); 68 } 69 70 public static void staticPrintESTrace(Exception e, PrintWriter os) 71 { 72 CharArrayWriter writer = new CharArrayWriter (); 73 PrintWriter pw = new PrintWriter (writer); 74 75 e.printStackTrace(pw); 76 77 pw.close(); 78 char []array = writer.toCharArray(); 79 80 CharBuffer cb = filter(array); 81 82 if (os != null) { 83 os.print(cb.toString()); 84 } else 85 System.out.println(cb); 86 } 87 88 public void printESStackTrace(OutputStream os) 89 { 90 staticPrintESTrace(this, os); 91 } 92 93 public void printESStackTrace() 94 { 95 printESStackTrace(System.out); 96 } 97 98 public void printESStackTrace(PrintWriter out) 99 { 100 CharArrayWriter writer = new CharArrayWriter (); 101 PrintWriter pw = new PrintWriter (writer); 102 103 printStackTrace(pw); 104 105 pw.close(); 106 char []array = writer.toCharArray(); 107 108 CharBuffer cb = filter(array); 109 110 out.print(cb.toString()); 111 } 112 113 117 private static CharBuffer filter(char []array) 118 { 119 CharBuffer buf = new CharBuffer(); 120 CharBuffer fun = new CharBuffer(); 121 CharBuffer file = new CharBuffer(); 122 123 boolean hasJavaScript = false; 124 int i = 0; 125 while (i < array.length) { 126 fun.clear(); 127 file.clear(); 128 int start = i; 129 int end; 130 for (end = i; end < array.length && array[end] != '\n'; end++) { 131 } 132 133 for (; i < end && Character.isWhitespace(array[i]); i++) { 134 fun.append(array[i]); 135 } 136 137 for (; i < end && ! Character.isWhitespace(array[i]); i++) { 139 fun.append(array[i]); 140 } 141 142 if (! fun.endsWith("at")) { 143 for (i = start; i < end; i++) { 144 buf.append(array[i]); 145 } 146 i = end + 1; 147 148 buf.append('\n'); 149 150 continue; 151 } 152 153 for (; i < end && Character.isWhitespace(array[i]); i++) { 154 } 155 156 fun.clear(); 157 for (; i < end && ! Character.isWhitespace(array[i]) && 158 array[i] != '('; i++) { 159 fun.append(array[i]); 160 } 161 162 if (fun.startsWith("com.caucho.es.")) { 163 i = end + 1; 164 continue; 165 } 166 167 184 185 if (i < end && array[i] == '(') 186 i++; 187 188 for (; i < end && array[i] != ')'; i++) { 189 file.append(array[i]); 190 } 191 192 i = end + 1; 193 194 if (fun.endsWith(".call")) 195 continue; 196 197 int p = fun.lastIndexOf('.'); 198 String className; 199 String function; 200 if (p > 0) { 201 className = fun.substring(0, p); 202 function = fun.substring(p + 1); 203 } 204 else { 205 className = ""; 206 function = fun.toString(); 207 } 208 209 Global global = Global.getGlobalProto(); 210 LineMap lineMap = global != null ? global.getLineMap(className) : null; 211 String line = file.toString(); 212 213 if (lineMap != null) { 214 p = file.indexOf(':'); 215 if (p > 0) { 216 try { 217 String filename = file.substring(0, p); 218 int lineNo = Integer.parseInt(file.substring(p + 1)); 219 line = lineMap.convertLine(filename, lineNo); 220 } catch (Exception e) { 221 } 222 } 223 else 224 line = lineMap.convertLine(file.toString(), 1); 225 } 226 227 buf.append("\tat "); 228 buf.append(fun); 229 buf.append("("); 230 buf.append(line); 231 buf.append(")"); 232 buf.append("\n"); 233 234 hasJavaScript = true; 235 } 236 237 return buf; 238 } 239 } 240 241 242 243 | Popular Tags |