You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/03/28 18:32:52 UTC

cvs commit: jakarta-log4j/src/java/org/apache/log4j/spi ThrowableInformation.java

ceki        01/03/28 08:32:52

  Added:       src/java/org/apache/log4j/spi ThrowableInformation.java
  Log:
  A helper class that can represent throwables even after serialization.
  
  Revision  Changes    Path
  1.1                  jakarta-log4j/src/java/org/apache/log4j/spi/ThrowableInformation.java
  
  Index: ThrowableInformation.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.APL file.  */
  
  package org.apache.log4j.spi;
  
  import java.io.Writer;
  import java.io.PrintWriter;
  import java.util.Vector;
  
  /**
     
  
  
   */
  public class ThrowableInformation implements java.io.Serializable {
  
  
    private transient Throwable throwable;
    private String[] rep;
    
    static private VectorWriter vw = new VectorWriter();
    
    public
    ThrowableInformation(Throwable throwable) {
      this.throwable = throwable;
    }
  
    public
    Throwable getThrowable() {
      return throwable;
    }
    
    public
    String[] getThrowableStrRep() {
      if(rep != null) {
        return (String[]) rep.clone();
      } else {
        throwable.printStackTrace(vw);
        rep = vw.toStringArray();
        vw.clear();
        return rep;
      }
    }
  
    
  }
  
  
  class VectorWriter extends PrintWriter {
      
    private Vector v;
    
    VectorWriter() {
      super(new NullWriter());
      v = new Vector();
    }
    
    public
    void println(Object o) {      
      v.add(o.toString());
    }
    
    // JDK 1.1.x apprenly uses this form of println while in
    // printStackTrace()
    public
    void println(char[] s) {
      v.add(new String(s));
    }
    
    public  
    void println(String s) {
      v.add(s);
    }
  
    public
    String[] toStringArray() {
      int len = v.size();
      String[] sa = new String[len];
      for(int i = 0; i < len; i++) {
        sa[i] = (String) v.elementAt(i);
      }
      return sa;
    }
  
    public
    void clear() {
      v.setSize(0);
    }
  }  
  
  class NullWriter extends Writer {    
    
    public 
    void close() {
    }
  
    public 
    void flush() {
    }
  
    public
    void write(char[] cbuf, int off, int len) {
    }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-cvs-help@jakarta.apache.org