Package de.aristaflow.adept2.util
Class StackTraceTools
- java.lang.Object
- 
- de.aristaflow.adept2.util.StackTraceTools
 
- 
 public final class StackTraceTools extends Object Provides tools to manipulate stack traces (i.e. arrays ofStackTraceElements.- Author:
- Patrick Schmidt
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetStackTrace()Gets the current stack as string.static StackTraceElement[]headTrim(StackTraceElement[] stackTrace, int trim)Removes the given number of elements from the head (i.e.static StackTraceElement[]headTrim(StackTraceElement[] origStackTrace, Class<?> cls)Removes all elements from the head of the stack trace that refer to the given class.static StackTraceElement[]join(StackTraceElement[] headStackTrace, int tailTrimOfHead, StackTraceElement[] tailStackTrace, int headTrimOfTail)Joins the two given stack traces, i.e.static StackTraceElement[]join(StackTraceElement[] headStackTrace, StackTraceElement[] tailStackTrace)Joins the two given stack traces, i.e.static voidprintStackTrace()Prints the current stack trace toSystem.out.static StringstackTracesToString(StackTraceElement[] trace)Returns the designated stack trace as string.static StringstackTraceToString(Throwable throwable)Returns the output ofThrowable.printStackTrace(PrintWriter)in a string.static StackTraceElement[]tailTrim(StackTraceElement[] stackTrace, int trim)Removes the given number of elements from the tail (i.e.
 
- 
- 
- 
Method Detail- 
tailTrimpublic static StackTraceElement[] tailTrim(StackTraceElement[] stackTrace, int trim) Removes the given number of elements from the tail (i.e. the bottom) of the given stack trace and returns the result in a new array.- Parameters:
- stackTrace- the stack trace to be trimmed
- trim- the number of elements to be trimmed from the stack trace's tail
- Returns:
- a new stack trace without the trimmed elements
 
 - 
headTrimpublic static StackTraceElement[] headTrim(StackTraceElement[] stackTrace, int trim) Removes the given number of elements from the head (i.e. the top) of the given stack trace and returns the result in a new array.- Parameters:
- stackTrace- the stack trace to be trimmed
- trim- the number of elements to be trimmed from the stack trace's head
- Returns:
- a new stack trace without the trimmed elements
 
 - 
headTrimpublic static StackTraceElement[] headTrim(StackTraceElement[] origStackTrace, Class<?> cls) Removes all elements from the head of the stack trace that refer to the given class.- Parameters:
- origStackTrace- the stack trace to be trimmed
- cls- the class for which to remove all elements from the head of the stack trace
- Returns:
- a new stack trace without the trimmed elements
 
 - 
joinpublic static StackTraceElement[] join(StackTraceElement[] headStackTrace, StackTraceElement[] tailStackTrace) Joins the two given stack traces, i.e. append the tail stack trace to the head stack trace, and returns the result in a new array.- Parameters:
- headStackTrace- the stack trace to which the tail stack trace will be appended
- tailStackTrace- the stack trace that will be appended to the head stack trace
- Returns:
- the joined stack traces
 
 - 
joinpublic static StackTraceElement[] join(StackTraceElement[] headStackTrace, int tailTrimOfHead, StackTraceElement[] tailStackTrace, int headTrimOfTail) Joins the two given stack traces, i.e. append the tail stack trace to the head stack trace, and returns the result in a new array. While doing so, the tail of the head stack trace and the head of the tail stack trace will be trimmed by the given numbers of elements.- Parameters:
- headStackTrace- the stack trace to which the tail stack trace will be appended
- tailTrimOfHead- the number of elements to be trimmed from the trail of the head stack trace
- tailStackTrace- the stack trace that will be appended to the head stack trace
- headTrimOfTail- the number of elements to be trimmed from the head of the tail stack trace
- Returns:
- the joined stack traces
 
 - 
stackTraceToStringpublic static String stackTraceToString(Throwable throwable) Returns the output ofThrowable.printStackTrace(PrintWriter)in a string.- Parameters:
- throwable- the throwable
- Returns:
- the output of Throwable.printStackTrace(PrintWriter)in a string
 
 - 
stackTracesToStringpublic static String stackTracesToString(StackTraceElement[] trace) Returns the designated stack trace as string.- Parameters:
- trace- The stack trace to be transformed to a string.
- Returns:
- The designated stack trace as string.
 
 - 
getStackTracepublic static String getStackTrace() Gets the current stack as string. This is the normal string representation of a throwable stack, i. e. using tabs and printing line numbers for each stack trace element.
 The call of this method will not be in the stack.- Returns:
- The current stack as string.
 
 - 
printStackTracepublic static void printStackTrace() Prints the current stack trace toSystem.out. This method is only useful for debugging purposes.
 
- 
 
-