Closer.java
4.69 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.google.common.io;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
@Beta
public final class Closer
implements Closeable
{
private static final c b;
@VisibleForTesting
final c a;
private final Deque<Closeable> c = new ArrayDeque(4);
private Throwable d;
static
{
if (b.a()) {}
for (Object localObject = b.a;; localObject = a.a)
{
b = (c)localObject;
return;
}
}
@VisibleForTesting
private Closer(c paramc)
{
this.a = ((c)Preconditions.checkNotNull(paramc));
}
public static Closer create()
{
return new Closer(b);
}
public final void close()
throws IOException
{
Object localObject = this.d;
while (!this.c.isEmpty())
{
Closeable localCloseable = (Closeable)this.c.removeFirst();
try
{
localCloseable.close();
}
catch (Throwable localThrowable)
{
if (localObject == null) {
localObject = localThrowable;
} else {
this.a.a(localCloseable, (Throwable)localObject, localThrowable);
}
}
}
if ((this.d == null) && (localObject != null))
{
Throwables.propagateIfPossible((Throwable)localObject, IOException.class);
throw new AssertionError(localObject);
}
}
public final <C extends Closeable> C register(@Nullable C paramC)
{
if (paramC != null) {
this.c.addFirst(paramC);
}
return paramC;
}
public final RuntimeException rethrow(Throwable paramThrowable)
throws IOException
{
Preconditions.checkNotNull(paramThrowable);
this.d = paramThrowable;
Throwables.propagateIfPossible(paramThrowable, IOException.class);
throw new RuntimeException(paramThrowable);
}
public final <X extends Exception> RuntimeException rethrow(Throwable paramThrowable, Class<X> paramClass)
throws IOException, Exception
{
Preconditions.checkNotNull(paramThrowable);
this.d = paramThrowable;
Throwables.propagateIfPossible(paramThrowable, IOException.class);
Throwables.propagateIfPossible(paramThrowable, paramClass);
throw new RuntimeException(paramThrowable);
}
public final <X1 extends Exception, X2 extends Exception> RuntimeException rethrow(Throwable paramThrowable, Class<X1> paramClass, Class<X2> paramClass1)
throws IOException, Exception, Exception
{
Preconditions.checkNotNull(paramThrowable);
this.d = paramThrowable;
Throwables.propagateIfPossible(paramThrowable, IOException.class);
Throwables.propagateIfPossible(paramThrowable, paramClass, paramClass1);
throw new RuntimeException(paramThrowable);
}
@VisibleForTesting
static final class a
implements Closer.c
{
static final a a = new a();
public final void a(Closeable paramCloseable, Throwable paramThrowable1, Throwable paramThrowable2)
{
paramThrowable1 = Closeables.a;
Level localLevel = Level.WARNING;
paramCloseable = String.valueOf(String.valueOf(paramCloseable));
paramThrowable1.log(localLevel, paramCloseable.length() + 42 + "Suppressing exception thrown when closing " + paramCloseable, paramThrowable2);
}
}
@VisibleForTesting
static final class b
implements Closer.c
{
static final b a = new b();
static final Method b = b();
static boolean a()
{
return b != null;
}
private static Method b()
{
try
{
Method localMethod = Throwable.class.getMethod("addSuppressed", new Class[] { Throwable.class });
return localMethod;
}
catch (Throwable localThrowable) {}
return null;
}
public final void a(Closeable paramCloseable, Throwable paramThrowable1, Throwable paramThrowable2)
{
if (paramThrowable1 == paramThrowable2) {
return;
}
try
{
b.invoke(paramThrowable1, new Object[] { paramThrowable2 });
return;
}
catch (Throwable localThrowable)
{
Closer.a.a.a(paramCloseable, paramThrowable1, paramThrowable2);
}
}
}
@VisibleForTesting
static abstract interface c
{
public abstract void a(Closeable paramCloseable, Throwable paramThrowable1, Throwable paramThrowable2);
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/io/Closer.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/