Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,6 @@ import java.io.InputStream;
|
||||
import java.io.NotSerializableException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectStreamClass;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -101,7 +100,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream {
|
||||
}
|
||||
}
|
||||
try {
|
||||
return Proxy.getProxyClass(this.classLoader, resolvedInterfaces);
|
||||
return ClassUtils.createCompositeInterface(resolvedInterfaces, this.classLoader);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new ClassNotFoundException(null, ex);
|
||||
@@ -117,7 +116,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream {
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
resolvedInterfaces[i] = resolveFallbackIfPossible(interfaces[i], ex);
|
||||
}
|
||||
return Proxy.getProxyClass(getFallbackClassLoader(), resolvedInterfaces);
|
||||
return ClassUtils.createCompositeInterface(resolvedInterfaces, getFallbackClassLoader());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,8 +138,9 @@ public class ConfigurableObjectInputStream extends ObjectInputStream {
|
||||
|
||||
/**
|
||||
* Return the fallback ClassLoader to use when no ClassLoader was specified
|
||||
* and ObjectInputStream's own default ClassLoader failed.
|
||||
* <p>The default implementation simply returns {@code null}.
|
||||
* and ObjectInputStream's own default class loader failed.
|
||||
* <p>The default implementation simply returns {@code null}, indicating
|
||||
* that no specific fallback is available.
|
||||
*/
|
||||
protected ClassLoader getFallbackClassLoader() throws IOException {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -72,7 +72,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns a File reference for the underlying class path
|
||||
* This implementation returns a File reference for the given URI-identified
|
||||
* resource, provided that it refers to a file in the file system.
|
||||
* @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String)
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -182,8 +182,8 @@ public class PathResource extends AbstractResource implements WritableResource {
|
||||
return this.path.toFile();
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// only Paths on the default file system can be converted to a File
|
||||
// do exception translation for cases where conversion is not possible
|
||||
// Only paths on the default file system can be converted to a File:
|
||||
// Do exception translation for cases where conversion is not possible.
|
||||
throw new FileNotFoundException(this.path + " cannot be resolved to " + "absolute file path");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,26 +37,26 @@ import java.net.URL;
|
||||
* @see #getFile()
|
||||
* @see WritableResource
|
||||
* @see ContextResource
|
||||
* @see FileSystemResource
|
||||
* @see ClassPathResource
|
||||
* @see UrlResource
|
||||
* @see ClassPathResource
|
||||
* @see FileSystemResource
|
||||
* @see PathResource
|
||||
* @see ByteArrayResource
|
||||
* @see InputStreamResource
|
||||
* @see PathResource
|
||||
*/
|
||||
public interface Resource extends InputStreamSource {
|
||||
|
||||
/**
|
||||
* Return whether this resource actually exists in physical form.
|
||||
* Determine whether this resource actually exists in physical form.
|
||||
* <p>This method performs a definitive existence check, whereas the
|
||||
* existence of a {@code Resource} handle only guarantees a
|
||||
* valid descriptor handle.
|
||||
* existence of a {@code Resource} handle only guarantees a valid
|
||||
* descriptor handle.
|
||||
*/
|
||||
boolean exists();
|
||||
|
||||
/**
|
||||
* Return whether the contents of this resource can be read,
|
||||
* e.g. via {@link #getInputStream()} or {@link #getFile()}.
|
||||
* Indicate whether the contents of this resource can be read via
|
||||
* {@link #getInputStream()}.
|
||||
* <p>Will be {@code true} for typical resource descriptors;
|
||||
* note that actual content reading may still fail when attempted.
|
||||
* However, a value of {@code false} is a definitive indication
|
||||
@@ -66,8 +66,8 @@ public interface Resource extends InputStreamSource {
|
||||
boolean isReadable();
|
||||
|
||||
/**
|
||||
* Return whether this resource represents a handle with an open
|
||||
* stream. If true, the InputStream cannot be read multiple times,
|
||||
* Indicate whether this resource represents a handle with an open stream.
|
||||
* If {@code true}, the InputStream cannot be read multiple times,
|
||||
* and must be read and closed to avoid resource leaks.
|
||||
* <p>Will be {@code false} for typical resource descriptors.
|
||||
*/
|
||||
@@ -84,6 +84,7 @@ public interface Resource extends InputStreamSource {
|
||||
* Return a URI handle for this resource.
|
||||
* @throws IOException if the resource cannot be resolved as URI,
|
||||
* i.e. if the resource is not available as descriptor
|
||||
* @since 2.5
|
||||
*/
|
||||
URI getURI() throws IOException;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -61,6 +61,7 @@ public class UrlResource extends AbstractFileResolvingResource {
|
||||
* Create a new {@code UrlResource} based on the given URI object.
|
||||
* @param uri a URI
|
||||
* @throws MalformedURLException if the given URL path is not valid
|
||||
* @since 2.5
|
||||
*/
|
||||
public UrlResource(URI uri) throws MalformedURLException {
|
||||
Assert.notNull(uri, "URI must not be null");
|
||||
|
||||
@@ -1158,7 +1158,6 @@ public abstract class ClassUtils {
|
||||
*/
|
||||
public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) {
|
||||
Assert.notEmpty(interfaces, "Interfaces must not be empty");
|
||||
Assert.notNull(classLoader, "ClassLoader must not be null");
|
||||
return Proxy.getProxyClass(classLoader, interfaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -235,6 +235,7 @@ public abstract class ResourceUtils {
|
||||
* @return a corresponding File object
|
||||
* @throws FileNotFoundException if the URL cannot be resolved to
|
||||
* a file in the file system
|
||||
* @since 2.5
|
||||
*/
|
||||
public static File getFile(URI resourceUri) throws FileNotFoundException {
|
||||
return getFile(resourceUri, "URI");
|
||||
@@ -249,6 +250,7 @@ public abstract class ResourceUtils {
|
||||
* @return a corresponding File object
|
||||
* @throws FileNotFoundException if the URL cannot be resolved to
|
||||
* a file in the file system
|
||||
* @since 2.5
|
||||
*/
|
||||
public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
|
||||
Assert.notNull(resourceUri, "Resource URI must not be null");
|
||||
|
||||
Reference in New Issue
Block a user