a
554325746@qq.com
2019-12-31 fa104829ecef68865e5e3bce174515009c6d687b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.basic.security.utils;
 
import java.util.ArrayList;
import java.util.List;
 
public class FrameUtil {
    public static List<String> getFrames() {
        List<String> frames = new ArrayList<>();
        try {
            throw new Exception();
        } catch (Exception e) {
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            String tab = "";
            for (StackTraceElement stackTraceElement : stackTraceElements) {
                tab += "    ";
                frames.add(
                        stackTraceElement.toString()
                );
            }
        }
        return frames;
    }
 
    public static List<String> getFrames(int frameIndex) {
        List<String> frames = new ArrayList<>();
        try {
            throw new Exception();
        } catch (Exception e) {
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            int i = 0;
            for (StackTraceElement stackTraceElement : stackTraceElements) {
                if (i == frameIndex) {
                    frames.add(stackTraceElement.toString());
                    break;
                }
                i++;
            }
        }
        return frames;
    }
 
    public static List<String> getFrames(String filter) {
        List<String> frames = new ArrayList<>();
        try {
            throw new Exception();
        } catch (Exception e) {
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            for (StackTraceElement stackTraceElement : stackTraceElements) {
                String frame = stackTraceElement.toString();
                if (frame != null && frame.contains(filter)) {
                    int index = 0;
                    for (int i = 0; i < frame.length(); i++) {
                        if (Character.isUpperCase(frame.charAt(i))) {
                            index = i;
                            break;
                        }
                    }
                    frames.add(frame.substring(index) + "\r\n");
                }
            }
        }
        return frames;
    }
}