protected static StackTraceElement[] parseStackTrace(String stacktrace) {
        try (BufferedReader reader = new BufferedReader(new StringReader(stacktrace))) {
            List<StackTraceElement> elements = new ArrayList<>();
            String line;
            // Example lines:
            // \tat io.apiman.gateway.engine.es.ESRegistry$1.completed(ESRegistry.java:79)
            // \tat org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)\r\n
            while ( (line = reader.readLine()) != null) {
                if (line.startsWith("\tat ")) { //$NON-NLS-1$
                    int openParenIdx = line.indexOf('(');
                    int closeParenIdx = line.indexOf(')');
                    String classAndMethod = line.substring(4, openParenIdx);
                    String fileAndLineNum = line.substring(openParenIdx + 1, closeParenIdx);
                    String className = classAndMethod.substring(0, classAndMethod.lastIndexOf('.'));
                    String methodName = classAndMethod.substring(classAndMethod.lastIndexOf('.') + 1);
                    String [] split = fileAndLineNum.split(":"); //$NON-NLS-1$
                    if (split.length == 1) {
                        elements.add(new StackTraceElement(className, methodName, fileAndLineNum, -1));
                    } else {
                        String fileName = split[0];
                        String lineNum = split[1];
                        elements.add(new StackTraceElement(className, methodName, fileName, new Integer(lineNum)));
                    }
                }
            }
            return elements.toArray(new StackTraceElement[elements.size()]);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
protected static StackTraceElement [ ] parseStackTrace ( String stacktrace ) { try ( BufferedReader reader = new BufferedReader ( new StringReader ( stacktrace ) ) ) { List < StackTraceElement > elements = new ArrayList < > ( ) ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { if ( line . startsWith ( "\tat " ) ) { int openParenIdx = line . indexOf ( '(' ) ; int closeParenIdx = line . indexOf ( ')' ) ; String classAndMethod = line . substring ( 4 , openParenIdx ) ; String fileAndLineNum = line . substring ( openParenIdx + 1 , closeParenIdx ) ; String className = classAndMethod . substring ( 0 , classAndMethod . lastIndexOf ( '.' ) ) ; String methodName = classAndMethod . substring ( classAndMethod . lastIndexOf ( '.' ) + 1 ) ; String [ ] split = fileAndLineNum . split ( ":" ) ; if ( split . length == 1 ) { elements . add ( new StackTraceElement ( className , methodName , fileAndLineNum , - 1 ) ) ; } else { String fileName = split [ 0 ] ; String lineNum = split [ 1 ] ; elements . add ( new StackTraceElement ( className , methodName , fileName , new Integer ( lineNum ) ) ) ; } } } return elements . toArray ( new StackTraceElement [ elements . size ( ) ] ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return null ; } }
Parses a stack trace from the given string.
@param stacktrace