1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.util.internal;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.IOException;
20 import java.io.PrintStream;
21 import java.util.List;
22
23 public final class ThrowableUtil {
24
25 private ThrowableUtil() { }
26
27
28
29
30 public static <T extends Throwable> T unknownStackTrace(T cause, Class<?> clazz, String method) {
31 cause.setStackTrace(new StackTraceElement[] { new StackTraceElement(clazz.getName(), method, null, -1)});
32 return cause;
33 }
34
35
36
37
38
39
40
41 @Deprecated
42 public static String stackTraceToString(Throwable cause) {
43 ByteArrayOutputStream out = new ByteArrayOutputStream();
44 PrintStream pout = new PrintStream(out);
45 cause.printStackTrace(pout);
46 pout.flush();
47 try {
48 return out.toString();
49 } finally {
50 try {
51 out.close();
52 } catch (IOException ignore) {
53
54 }
55 }
56 }
57
58 @Deprecated
59 public static boolean haveSuppressed() {
60 return true;
61 }
62
63 public static void addSuppressed(Throwable target, Throwable suppressed) {
64 if (suppressed != null) {
65 target.addSuppressed(suppressed);
66 }
67 }
68
69 public static void addSuppressedAndClear(Throwable target, List<Throwable> suppressed) {
70 addSuppressed(target, suppressed);
71 suppressed.clear();
72 }
73
74 public static void addSuppressed(Throwable target, List<Throwable> suppressed) {
75 for (Throwable t : suppressed) {
76 addSuppressed(target, t);
77 }
78 }
79
80 public static Throwable[] getSuppressed(Throwable source) {
81 return source.getSuppressed();
82 }
83 }