Class StackTrace
- java.lang.Object
-
- com.github.toolarium.common.stacktrace.StackTrace
-
public final class StackTrace extends java.lang.ObjectThe StackInfo class is a collection of static methods to allow users to quickly determine the call stack. This class makes it possible to determine what class called a method and what text files and line numbers resulted in stack calls. The StackInfo calls will not appear in return string. By calling the method getTrace a 2D-String-Array is returned.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<java.lang.String>DEFAULT_EXCLUDESDefault Stacktrace exclues
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StackTraceElement[]filterStackTrace(java.lang.StackTraceElement[] elements)Filter the given trace elements as stack tracestatic java.lang.StackTraceElement[]filterStackTrace(java.lang.StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames)Filter the given trace elements as stack tracestatic java.lang.StringgetStackTrace()Create the current stack tracestatic java.lang.StringgetStackTrace(int traceSize)Create the current stack tracestatic java.lang.StringgetStackTrace(StackTraceElement[] elements)Prepares the given trace elements as stack tracestatic java.lang.StringgetStackTrace(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames)Prepares the given trace elements as stack tracestatic java.lang.StringgetStackTrace(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames, java.lang.String header)Prepares the given trace elements as stack tracestatic java.lang.StringgetStackTrace(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames, java.lang.String header, java.lang.String newline)Prepares the given trace elements as stack tracestatic StackTraceElement[]getStackTraceElements()Parse the stack tracestatic StackTraceElement[]getStackTraceElements(int numberOfLastElements)Parse the stack tracestatic StackTraceElement[]getStackTraceElements(int startIndex, int numberOfLastElements)Parse the stack tracestatic StackTraceElementparseStackTraceElement(java.lang.String line)Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling classstatic StackTraceElement[]parseStackTraceElements(java.lang.String callStack, int startIndex, int traceSize)Parse the stack trace into the desired two dimensional stringstatic StackTraceElement[]parseStackTraceElements(java.lang.Throwable t, int startTrace, int traceSize)Parse the stack trace into the desired two dimensional stringstatic java.lang.String[]parseStackTraceLine(java.lang.String line)Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling classstatic voidprocessStackTrace(java.util.function.Consumer<java.lang.String> consumer)Process the current stack tracestatic voidprocessStackTrace(java.util.function.Consumer<java.lang.String> consumer, int traceSize)Process the current stack tracestatic voidprocessStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames)Create the current stack tracestatic voidprocessStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames, java.lang.String header)Create the current stack tracestatic voidprocessStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames, java.lang.String header, int traceSize)Create the current stack tracestatic voidprocessStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames, java.lang.String header, java.lang.String newline, int traceSize)Create the current stack trace
-
-
-
Method Detail
-
getStackTraceElements
public static StackTraceElement[] getStackTraceElements()
Parse the stack trace- Returns:
- an array with stack trace elements.
-
getStackTraceElements
public static StackTraceElement[] getStackTraceElements(int numberOfLastElements)
Parse the stack trace- Parameters:
numberOfLastElements- the number of the last elements in stack trace- Returns:
- an array with stack trace elements.
-
getStackTraceElements
public static StackTraceElement[] getStackTraceElements(int startIndex, int numberOfLastElements)
Parse the stack trace- Parameters:
startIndex- the start indexnumberOfLastElements- the number of the last elements in stack trace- Returns:
- an array with stack trace elements.
-
getStackTrace
public static java.lang.String getStackTrace()
Create the current stack trace- Returns:
- the stack trace
-
getStackTrace
public static java.lang.String getStackTrace(int traceSize)
Create the current stack trace- Parameters:
traceSize- the size of the stack trace (default -1)- Returns:
- the stack trace
-
getStackTrace
public static java.lang.String getStackTrace(StackTraceElement[] elements)
Prepares the given trace elements as stack trace- Parameters:
elements- the elements- Returns:
- the prepared stack trace
-
getStackTrace
public static java.lang.String getStackTrace(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames)
Prepares the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filtered- Returns:
- the prepared stack trace
-
getStackTrace
public static java.lang.String getStackTrace(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames, java.lang.String header)
Prepares the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filteredheader- the header- Returns:
- the prepared stack trace
-
getStackTrace
public static java.lang.String getStackTrace(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames, java.lang.String header, java.lang.String newline)
Prepares the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filteredheader- the headernewline- the newline- Returns:
- the prepared stack trace
-
processStackTrace
public static void processStackTrace(java.util.function.Consumer<java.lang.String> consumer)
Process the current stack trace- Parameters:
consumer- the consumer
-
processStackTrace
public static void processStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames)Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filtered
-
processStackTrace
public static void processStackTrace(java.util.function.Consumer<java.lang.String> consumer, int traceSize)Process the current stack trace- Parameters:
consumer- the consumertraceSize- the size of the stack trace (default -1)
-
processStackTrace
public static void processStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames, java.lang.String header)Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filteredheader- the header
-
processStackTrace
public static void processStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames, java.lang.String header, int traceSize)Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filteredheader- the headertraceSize- the size of the stack trace (default -1)
-
processStackTrace
public static void processStackTrace(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames, java.lang.String header, java.lang.String newline, int traceSize)Create the current stack trace- Parameters:
consumer- the consumerfilteredClassNames- a list of element names which should be filteredheader- the headernewline- the newlinetraceSize- the size of the stack trace (default -1)
-
filterStackTrace
public static java.lang.StackTraceElement[] filterStackTrace(java.lang.StackTraceElement[] elements)
Filter the given trace elements as stack trace- Parameters:
elements- the elements- Returns:
- the prepared stack trace
-
filterStackTrace
public static java.lang.StackTraceElement[] filterStackTrace(java.lang.StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames)Filter the given trace elements as stack trace- Parameters:
elements- the elementsfilteredClassNames- a list of element names which should be filtered- Returns:
- the prepared stack trace
-
parseStackTraceElements
public static StackTraceElement[] parseStackTraceElements(java.lang.Throwable t, int startTrace, int traceSize) throws java.io.IOException
Parse the stack trace into the desired two dimensional string- Parameters:
t- the exceptionstartTrace- the start of the trace (default 2)traceSize- the stack trace size (default -1)- Returns:
- a formated two dimensional string:
Each row representate a call on the stack and the columns
are formated like below:
- member 0 : name of text file from which call was made
- member 1 : line number of text file from which call was made
- member 2 : method name of calling class
- member 3 : name of calling class
- member 4 : full package name of calling class
- Throws:
java.io.IOException- in case of error
-
parseStackTraceElements
public static StackTraceElement[] parseStackTraceElements(java.lang.String callStack, int startIndex, int traceSize)
Parse the stack trace into the desired two dimensional string- Parameters:
callStack- the stack trace to parsestartIndex- the start of the trace (default 2)traceSize- the stack trace size (default -1)- Returns:
- a formated two dimensional string:
Each row representate a call on the stack and the columns
are formated like below:
- member 0 : name of text file from which call was made
- member 1 : line number of text file from which call was made
- member 2 : method name of calling class
- member 3 : name of calling class
- member 4 : full package name of calling class
-
parseStackTraceElement
public static StackTraceElement parseStackTraceElement(java.lang.String line)
Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling class- Parameters:
line- a line from the stack trace- Returns:
- a stack trace element
-
parseStackTraceLine
public static java.lang.String[] parseStackTraceLine(java.lang.String line)
Break a line from the stack trace into the format: member 0 : name of text file from which call was made member 1 : line number of text file from which call was made member 2 : method name of calling class member 3 : name of calling class member 4 : full package name of calling class- Parameters:
line- a line from the stack trace- Returns:
- a formated stack trace array:
- member 0 : name of text file from which call was made
- member 1 : line number of text file from which call was made
- member 2 : method name of calling class
- member 3 : name of calling class
- member 4 : full package name of calling class
-
-