1 package org.apache.continuum.utils;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.PrintWriter;
23 import java.io.StringWriter;
24
25 /**
26 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
27 * @version $Id: ContinuumUtils.java 734441 2009-01-14 16:31:04Z ctan $
28 */
29 public class ContinuumUtils
30 {
31 public static final String EOL = System.getProperty( "line.separator" );
32
33 public static String throwableToString( Throwable error )
34 {
35 if ( error == null )
36 {
37 return "";
38 }
39
40 StringWriter writer = new StringWriter();
41
42 PrintWriter printer = new PrintWriter( writer );
43
44 error.printStackTrace( printer );
45
46 printer.flush();
47
48 return writer.getBuffer().toString();
49 }
50
51 public static String throwableMessagesToString( Throwable error )
52 {
53 if ( error == null )
54 {
55 return "";
56 }
57
58 StringBuffer buffer = new StringBuffer();
59
60 buffer.append( error.getMessage() );
61
62 error = error.getCause();
63
64 while ( error != null )
65 {
66 buffer.append( EOL );
67
68 buffer.append( error.getMessage() );
69
70 error = error.getCause();
71 }
72
73 return buffer.toString();
74 }
75 }