You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jo...@locus.apache.org on 2000/11/08 03:29:08 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/util StringUtils.java

jon         00/11/07 18:29:08

  Modified:    src/java/org/apache/velocity/util StringUtils.java
  Log:
  added stackTrace method that converts a stack trace to a string
  
  Revision  Changes    Path
  1.3       +25 -3     jakarta-velocity/src/java/org/apache/velocity/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/StringUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringUtils.java	2000/10/24 23:34:41	1.2
  +++ StringUtils.java	2000/11/08 02:29:06	1.3
  @@ -54,8 +54,7 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.File;
  -import java.io.FileReader;
  +import java.io.*;
   
   import java.util.Hashtable;
   import java.util.StringTokenizer;
  @@ -69,7 +68,7 @@
    * string utilities class.
    *
    *  @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  - *  @version $Id: StringUtils.java,v 1.2 2000/10/24 23:34:41 jvanzyl Exp $
  + *  @version $Id: StringUtils.java,v 1.3 2000/11/08 02:29:06 jon Exp $
    */
   public class StringUtils
   {
  @@ -243,5 +242,28 @@
               return buf.toString();
           }
           return line;
  +    }
  +    
  +    /**
  +     * Returns the output of printStackTrace as a String.
  +     *
  +     * @param e A Throwable.
  +     * @return A String.
  +     */
  +    public static final String stackTrace(Throwable e)
  +    {
  +        String foo = null;
  +        try
  +        {
  +            // And show the Error Screen.
  +            ByteArrayOutputStream ostr = new ByteArrayOutputStream();
  +            e.printStackTrace( new PrintWriter(ostr,true) );
  +            foo = ostr.toString();
  +        }
  +        catch (Exception f)
  +        {
  +            // Do nothing.
  +        }
  +        return foo;
       }
   }