View Javadoc
1   package org.codehaus.plexus.util;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.PrintWriter;
20  import java.io.StringWriter;
21  
22  /**
23   * Convenience class to handle throwable stacktraces
24   * <p>
25   * Created on 18/06/2003
26   * </p>
27   *
28   * @author <a href="mailto:bert@tuaworks.co.nz">Bert van Brakel</a>
29   * @version $Revision$
30   */
31  public class Tracer
32  {
33  
34      /**
35       * Constructor
36       */
37      private Tracer()
38      {
39          super();
40      }
41  
42      /**
43       * Return the throwable stack trace as a string
44       */
45      public static String traceToString( Throwable t )
46      {
47          if ( t == null )
48          {
49              return null;
50          }
51          StringWriter sw = new StringWriter();
52          t.printStackTrace( new PrintWriter( sw ) );
53          return sw.toString();
54      }
55  
56  }