@ -76,7 +76,13 @@ public class LaunchedURLClassLoader extends URLClassLoader {
if ( name . equals ( "" ) & & hasURLs ( ) ) {
return getURLs ( ) [ 0 ] ;
}
return super . findResource ( name ) ;
Handler . setUseFastConnectionExceptions ( true ) ;
try {
return super . findResource ( name ) ;
}
finally {
Handler . setUseFastConnectionExceptions ( false ) ;
}
}
catch ( IllegalArgumentException ex ) {
return null ;
@ -88,7 +94,13 @@ public class LaunchedURLClassLoader extends URLClassLoader {
if ( name . equals ( "" ) & & hasURLs ( ) ) {
return Collections . enumeration ( Arrays . asList ( getURLs ( ) ) ) ;
}
return super . findResources ( name ) ;
Handler . setUseFastConnectionExceptions ( true ) ;
try {
return super . findResources ( name ) ;
}
finally {
Handler . setUseFastConnectionExceptions ( false ) ;
}
}
private boolean hasURLs ( ) {
@ -100,33 +112,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
if ( this . rootClassLoader = = null ) {
return findResources ( name ) ;
}
final Enumeration < URL > rootResources = this . rootClassLoader . getResources ( name ) ;
final Enumeration < URL > localResources = findResources ( name ) ;
return new Enumeration < URL > ( ) {
@Override
public boolean hasMoreElements ( ) {
try {
Handler . setUseFastConnectionExceptions ( true ) ;
return rootResources . hasMoreElements ( )
| | localResources . hasMoreElements ( ) ;
}
finally {
Handler . setUseFastConnectionExceptions ( false ) ;
}
}
@Override
public URL nextElement ( ) {
if ( rootResources . hasMoreElements ( ) ) {
return rootResources . nextElement ( ) ;
}
return localResources . nextElement ( ) ;
}
} ;
return new ResourceEnumeration ( this . rootClassLoader . getResources ( name ) ,
findResources ( name ) ) ;
}
/ * *
@ -162,6 +149,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
}
}
catch ( Exception ex ) {
}
// 2) Try to find locally
@ -171,6 +159,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
return cls ;
}
catch ( Exception ex ) {
}
// 3) Use standard loading
@ -265,4 +254,41 @@ public class LaunchedURLClassLoader extends URLClassLoader {
}
}
/ * *
* { @link Enumeration } implementation used for { @code getResources ( ) } .
* /
private static class ResourceEnumeration implements Enumeration < URL > {
private final Enumeration < URL > rootResources ;
private final Enumeration < URL > localResources ;
ResourceEnumeration ( Enumeration < URL > rootResources ,
Enumeration < URL > localResources ) {
this . rootResources = rootResources ;
this . localResources = localResources ;
}
@Override
public boolean hasMoreElements ( ) {
try {
Handler . setUseFastConnectionExceptions ( true ) ;
return this . rootResources . hasMoreElements ( )
| | this . localResources . hasMoreElements ( ) ;
}
finally {
Handler . setUseFastConnectionExceptions ( false ) ;
}
}
@Override
public URL nextElement ( ) {
if ( this . rootResources . hasMoreElements ( ) ) {
return this . rootResources . nextElement ( ) ;
}
return this . localResources . nextElement ( ) ;
}
}
}