19
19
import java .io .ByteArrayOutputStream ;
20
20
import java .io .FileNotFoundException ;
21
21
import java .io .FilePermission ;
22
- import java .io .FilterInputStream ;
23
22
import java .io .IOException ;
24
23
import java .io .InputStream ;
25
24
import java .io .UnsupportedEncodingException ;
@@ -81,18 +80,14 @@ protected URLConnection openConnection(URL u) throws IOException {
81
80
82
81
private final JarEntryName jarEntryName ;
83
82
84
- private final CloseAction closeAction ;
85
-
86
83
private JarEntry jarEntry ;
87
84
88
- private JarURLConnection (URL url , JarFile jarFile , JarEntryName jarEntryName , CloseAction closeAction )
89
- throws IOException {
85
+ private JarURLConnection (URL url , JarFile jarFile , JarEntryName jarEntryName ) throws IOException {
90
86
// What we pass to super is ultimately ignored
91
87
super (EMPTY_JAR_URL );
92
88
this .url = url ;
93
89
this .jarFile = jarFile ;
94
90
this .jarEntryName = jarEntryName ;
95
- this .closeAction = closeAction ;
96
91
}
97
92
98
93
@ Override
@@ -173,17 +168,7 @@ public InputStream getInputStream() throws IOException {
173
168
if (inputStream == null ) {
174
169
throwFileNotFound (this .jarEntryName , this .jarFile );
175
170
}
176
- return new FilterInputStream (inputStream ) {
177
-
178
- @ Override
179
- public void close () throws IOException {
180
- super .close ();
181
- if (JarURLConnection .this .closeAction != null ) {
182
- JarURLConnection .this .closeAction .perform ();
183
- }
184
- }
185
-
186
- };
171
+ return inputStream ;
187
172
}
188
173
189
174
private void throwFileNotFound (Object entry , JarFile jarFile ) throws FileNotFoundException {
@@ -264,30 +249,24 @@ static JarURLConnection get(URL url, JarFile jarFile) throws IOException {
264
249
int index = indexOfRootSpec (spec , jarFile .getPathFromRoot ());
265
250
if (index == -1 ) {
266
251
return (Boolean .TRUE .equals (useFastExceptions .get ()) ? NOT_FOUND_CONNECTION
267
- : new JarURLConnection (url , null , EMPTY_JAR_ENTRY_NAME , null ));
252
+ : new JarURLConnection (url , null , EMPTY_JAR_ENTRY_NAME ));
268
253
}
269
254
int separator ;
270
- JarFile connectionJarFile = jarFile ;
271
255
while ((separator = spec .indexOf (SEPARATOR , index )) > 0 ) {
272
256
JarEntryName entryName = JarEntryName .get (spec .subSequence (index , separator ));
273
257
JarEntry jarEntry = jarFile .getJarEntry (entryName .toCharSequence ());
274
258
if (jarEntry == null ) {
275
- return JarURLConnection .notFound (connectionJarFile , entryName ,
276
- (connectionJarFile != jarFile ) ? connectionJarFile ::close : null );
259
+ return JarURLConnection .notFound (jarFile , entryName );
277
260
}
278
- connectionJarFile = connectionJarFile .getNestedJarFile (jarEntry );
261
+ jarFile = jarFile .getNestedJarFile (jarEntry );
279
262
index = separator + SEPARATOR .length ();
280
263
}
281
264
JarEntryName jarEntryName = JarEntryName .get (spec , index );
282
265
if (Boolean .TRUE .equals (useFastExceptions .get ()) && !jarEntryName .isEmpty ()
283
- && !connectionJarFile .containsEntry (jarEntryName .toString ())) {
284
- if (connectionJarFile != jarFile ) {
285
- connectionJarFile .close ();
286
- }
266
+ && !jarFile .containsEntry (jarEntryName .toString ())) {
287
267
return NOT_FOUND_CONNECTION ;
288
268
}
289
- return new JarURLConnection (url , new JarFile (connectionJarFile ), jarEntryName ,
290
- (connectionJarFile != jarFile ) ? connectionJarFile ::close : null );
269
+ return new JarURLConnection (url , new JarFile (jarFile ), jarEntryName );
291
270
}
292
271
293
272
private static int indexOfRootSpec (StringSequence file , String pathFromRoot ) {
@@ -300,22 +279,18 @@ private static int indexOfRootSpec(StringSequence file, String pathFromRoot) {
300
279
301
280
private static JarURLConnection notFound () {
302
281
try {
303
- return notFound (null , null , null );
282
+ return notFound (null , null );
304
283
}
305
284
catch (IOException ex ) {
306
285
throw new IllegalStateException (ex );
307
286
}
308
287
}
309
288
310
- private static JarURLConnection notFound (JarFile jarFile , JarEntryName jarEntryName , CloseAction closeAction )
311
- throws IOException {
289
+ private static JarURLConnection notFound (JarFile jarFile , JarEntryName jarEntryName ) throws IOException {
312
290
if (Boolean .TRUE .equals (useFastExceptions .get ())) {
313
- if (closeAction != null ) {
314
- closeAction .perform ();
315
- }
316
291
return NOT_FOUND_CONNECTION ;
317
292
}
318
- return new JarURLConnection (null , jarFile , jarEntryName , closeAction );
293
+ return new JarURLConnection (null , jarFile , jarEntryName );
319
294
}
320
295
321
296
/**
@@ -418,15 +393,4 @@ static JarEntryName get(StringSequence spec, int beginIndex) {
418
393
419
394
}
420
395
421
- /**
422
- * An action to be taken when the connection is being "closed" and its underlying
423
- * resources are no longer needed.
424
- */
425
- @ FunctionalInterface
426
- private interface CloseAction {
427
-
428
- void perform () throws IOException ;
429
-
430
- }
431
-
432
396
}
0 commit comments