Polishing

This commit is contained in:
Juergen Hoeller
2017-05-03 13:45:29 +02:00
parent d74542ed21
commit 27057889f8
3 changed files with 24 additions and 23 deletions

View File

@@ -125,8 +125,10 @@ public abstract class AbstractResource implements Resource {
}
/**
* This implementation returns {@link Channels#newChannel(InputStream)} with the result of
* {@link #getInputStream()}.
* This implementation returns {@link Channels#newChannel(InputStream)}
* with the result of {@link #getInputStream()}.
* <p>This is the same as in {@link Resource}'s corresponding default method
* but mirrored here for efficient JVM-level dispatching in a class hierarchy.
*/
@Override
public ReadableByteChannel readableChannel() throws IOException {
@@ -138,7 +140,6 @@ public abstract class AbstractResource implements Resource {
* content length. Subclasses will almost always be able to provide
* a more optimal version of this, e.g. checking a File length.
* @see #getInputStream()
* @throws IllegalStateException if {@link #getInputStream()} returns null.
*/
@Override
public long contentLength() throws IOException {

View File

@@ -28,6 +28,7 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.io.UrlResource;
import org.springframework.util.Assert;
@@ -60,10 +61,6 @@ import org.springframework.util.StringUtils;
*/
public abstract class SpringFactoriesLoader {
private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
private static Map<ClassLoader, MultiValueMap<String, String>> cache = new ConcurrentReferenceHashMap<>();
/**
* The location to look for factories.
* <p>Can be present in multiple JAR files.
@@ -71,10 +68,15 @@ public abstract class SpringFactoriesLoader {
public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories";
private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
private static final Map<ClassLoader, MultiValueMap<String, String>> cache = new ConcurrentReferenceHashMap<>();
/**
* Load and instantiate the factory implementations of the given type from
* {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader.
* <p>The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}.
* <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}.
* <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames}
* to obtain all registered factory names.
* @param factoryClass the interface or abstract class representing the factory
@@ -113,19 +115,17 @@ public abstract class SpringFactoriesLoader {
*/
public static List<String> loadFactoryNames(Class<?> factoryClass, ClassLoader classLoader) {
String factoryClassName = factoryClass.getName();
return loadSpringFactories(classLoader).getOrDefault(factoryClassName,
Collections.emptyList());
return loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList());
}
private static Map<String, List<String>> loadSpringFactories(
ClassLoader classLoader) {
private static Map<String, List<String>> loadSpringFactories(ClassLoader classLoader) {
MultiValueMap<String, String> result = cache.get(classLoader);
if (result != null)
return result;
try {
Enumeration<URL> urls = (classLoader != null
? classLoader.getResources(FACTORIES_RESOURCE_LOCATION)
: ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
Enumeration<URL> urls = (classLoader != null ?
classLoader.getResources(FACTORIES_RESOURCE_LOCATION) :
ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
result = new LinkedMultiValueMap<>();
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
@@ -141,8 +141,8 @@ public abstract class SpringFactoriesLoader {
return result;
}
catch (IOException ex) {
throw new IllegalArgumentException("Unable to load factories from location ["
+ FACTORIES_RESOURCE_LOCATION + "]", ex);
throw new IllegalArgumentException("Unable to load factories from location [" +
FACTORIES_RESOURCE_LOCATION + "]", ex);
}
}