commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
Date Thu, 01 Aug 2002 20:15:43 GMT
bayard      2002/08/01 13:15:43

  Modified:    lang/src/java/org/apache/commons/lang StringUtils.java
  Log:
  Added a stackTrace method. Possibly needs renaming. It's in common use in
  other Jakarta projects such as Ant. Turns a Throwable into a String.
  
  Revision  Changes    Path
  1.6       +15 -1     jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StringUtils.java	26 Jul 2002 01:40:11 -0000	1.5
  +++ StringUtils.java	1 Aug 2002 20:15:43 -0000	1.6
  @@ -60,6 +60,7 @@
   import java.io.OutputStreamWriter;
   import java.io.OutputStream;
   import java.io.PrintWriter;
  +import java.io.StringWriter;
   import java.io.IOException;
   import java.util.NoSuchElementException;
   import java.util.StringTokenizer;
  @@ -1565,6 +1566,19 @@
           // Step 7
           return d[n][m];
       }
  +
  +    /**
  +     * Convenient method to retrieve the full stacktrace from a given exception.     *
@param t the exception to get the stacktrace from.
  +     * @return the stacktrace from the given exception.
  +     */
  +    public static String getStackTrace(Throwable t) {
  +        StringWriter sw = new StringWriter();
  +        PrintWriter pw = new PrintWriter(sw, true);
  +        t.printStackTrace(pw);
  +        pw.flush();
  +        pw.close();
  +        return sw.toString();
  +    }   
   
   // these are not really of use in the Java world. Only if you're a C afficionado
   //    public static String sprintf(String format, Object[] list);
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message