1 16 17 package org.apache.log4j.spi; 18 19 import java.io.Writer ; 20 import java.io.PrintWriter ; 21 import java.util.Vector ; 22 23 36 public class ThrowableInformation implements java.io.Serializable { 37 38 static final long serialVersionUID = -4748765566864322735L; 39 40 private transient Throwable throwable; 41 private String [] rep; 42 43 public 44 ThrowableInformation(Throwable throwable) { 45 this.throwable = throwable; 46 } 47 48 public 49 Throwable getThrowable() { 50 return throwable; 51 } 52 53 public 54 String [] getThrowableStrRep() { 55 if(rep != null) { 56 return (String []) rep.clone(); 57 } else { 58 VectorWriter vw = new VectorWriter(); 59 throwable.printStackTrace(vw); 60 rep = vw.toStringArray(); 61 return rep; 62 } 63 } 64 } 65 66 75 class VectorWriter extends PrintWriter { 76 77 private Vector v; 78 79 VectorWriter() { 80 super(new NullWriter()); 81 v = new Vector (); 82 } 83 84 public void print(Object o) { 85 v.addElement(o.toString()); 86 } 87 88 public void print(char[] chars) { 89 v.addElement(new String (chars)); 90 } 91 92 public void print(String s) { 93 v.addElement(s); 94 } 95 96 public void println(Object o) { 97 v.addElement(o.toString()); 98 } 99 100 public 103 void println(char[] chars) { 104 v.addElement(new String (chars)); 105 } 106 107 public 108 void println(String s) { 109 v.addElement(s); 110 } 111 112 public void write(char[] chars) { 113 v.addElement(new String (chars)); 114 } 115 116 public void write(char[] chars, int off, int len) { 117 v.addElement(new String (chars, off, len)); 118 } 119 120 public void write(String s, int off, int len) { 121 v.addElement(s.substring(off, off+len)); 122 } 123 124 public void write(String s) { 125 v.addElement(s); 126 } 127 128 public String [] toStringArray() { 129 int len = v.size(); 130 String [] sa = new String [len]; 131 for(int i = 0; i < len; i++) { 132 sa[i] = (String ) v.elementAt(i); 133 } 134 return sa; 135 } 136 137 } 138 139 class NullWriter extends Writer { 140 141 public void close() { 142 } 144 145 public void flush() { 146 } 148 149 public void write(char[] cbuf, int off, int len) { 150 } 152 } 153 154 | Popular Tags |