Class StackTrace


  • public final class StackTrace
    extends java.lang.Object
    The 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_EXCLUDES
      Default 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 trace
      static java.lang.StackTraceElement[] filterStackTrace​(java.lang.StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames)
      Filter the given trace elements as stack trace
      static java.lang.String getStackTrace()
      Create the current stack trace
      static java.lang.String getStackTrace​(int traceSize)
      Create the current stack trace
      static java.lang.String getStackTrace​(StackTraceElement[] elements)
      Prepares the given trace elements as stack trace
      static java.lang.String getStackTrace​(StackTraceElement[] elements, java.util.List<java.lang.String> filteredClassNames)
      Prepares the given trace elements as stack trace
      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
      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
      static StackTraceElement[] getStackTraceElements()
      Parse the stack trace
      static StackTraceElement[] getStackTraceElements​(int numberOfLastElements)
      Parse the stack trace
      static StackTraceElement[] getStackTraceElements​(int startIndex, int numberOfLastElements)
      Parse the stack trace
      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
      static StackTraceElement[] parseStackTraceElements​(java.lang.String callStack, int startIndex, int traceSize)
      Parse the stack trace into the desired two dimensional string
      static StackTraceElement[] parseStackTraceElements​(java.lang.Throwable t, int startTrace, int traceSize)
      Parse the stack trace into the desired two dimensional string
      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
      static void processStackTrace​(java.util.function.Consumer<java.lang.String> consumer)
      Process the current stack trace
      static void processStackTrace​(java.util.function.Consumer<java.lang.String> consumer, int traceSize)
      Process the current stack trace
      static void processStackTrace​(java.util.function.Consumer<java.lang.String> consumer, java.util.List<java.lang.String> filteredClassNames)
      Create the current stack trace
      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
      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
      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_EXCLUDES

        public static final java.util.List<java.lang.String> DEFAULT_EXCLUDES
        Default Stacktrace exclues
    • 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 index
        numberOfLastElements - 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 elements
        filteredClassNames - 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 elements
        filteredClassNames - a list of element names which should be filtered
        header - 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 elements
        filteredClassNames - a list of element names which should be filtered
        header - the header
        newline - 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 consumer
        filteredClassNames - 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 consumer
        traceSize - 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 consumer
        filteredClassNames - a list of element names which should be filtered
        header - 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 consumer
        filteredClassNames - a list of element names which should be filtered
        header - the header
        traceSize - 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 consumer
        filteredClassNames - a list of element names which should be filtered
        header - the header
        newline - the newline
        traceSize - 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 elements
        filteredClassNames - 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 exception
        startTrace - 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 parse
        startIndex - 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