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 public static String stackTraceToString(Throwable cause) {
42 ByteArrayOutputStream out = new ByteArrayOutputStream();
43 PrintStream pout = new PrintStream(out);
44 cause.printStackTrace(pout);
45 pout.flush();
46 try {
47 return new String(out.toByteArray());
48 } finally {
49 try {
50 out.close();
51 } catch (IOException ignore) {
52
53 }
54 }
55 }
56
57 @Deprecated
58 public static boolean haveSuppressed() {
59 return true;
60 }
61
62 public static void addSuppressed(Throwable target, Throwable suppressed) {
63 target.addSuppressed(suppressed);
64 }
65
66 public static void addSuppressedAndClear(Throwable target, List<Throwable> suppressed) {
67 addSuppressed(target, suppressed);
68 suppressed.clear();
69 }
70
71 public static void addSuppressed(Throwable target, List<Throwable> suppressed) {
72 for (Throwable t : suppressed) {
73 addSuppressed(target, t);
74 }
75 }
76
77 public static Throwable[] getSuppressed(Throwable source) {
78 return source.getSuppressed();
79 }
80 }