Polishing
This commit is contained in:
parent
2270df515b
commit
e4e6910122
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -49,6 +49,7 @@ public class UrlResource extends AbstractFileResolvingResource {
|
|||
|
||||
private static final String AUTHORIZATION = "Authorization";
|
||||
|
||||
|
||||
/**
|
||||
* Original URI, if available; used for URI and File access.
|
||||
*/
|
||||
|
|
@ -310,7 +311,8 @@ public class UrlResource extends AbstractFileResolvingResource {
|
|||
/**
|
||||
* This delegate creates a {@code java.net.URL}, applying the given path
|
||||
* relative to the path of the underlying URL of this resource descriptor.
|
||||
* A leading slash will get dropped; a "#" symbol will get encoded.
|
||||
* <p>A leading slash will get dropped; a "#" symbol will get encoded.
|
||||
* Note that this method effectively cleans the combined path as of 6.1.
|
||||
* @since 5.2
|
||||
* @see #createRelative(String)
|
||||
* @see ResourceUtils#toRelativeURL(URL, String)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
|
@ -34,7 +34,7 @@ import org.springframework.lang.Nullable;
|
|||
* <p>Consider using Spring's Resource abstraction in the core package
|
||||
* for handling all kinds of file resources in a uniform manner.
|
||||
* {@link org.springframework.core.io.ResourceLoader}'s {@code getResource()}
|
||||
* method can resolve any location to an {@link org.springframework.core.io.Resource}
|
||||
* method can resolve any location to a {@link org.springframework.core.io.Resource}
|
||||
* object, which in turn allows one to obtain a {@code java.io.File} in the
|
||||
* file system through its {@code getFile()} method.
|
||||
*
|
||||
|
|
@ -101,6 +101,7 @@ public abstract class ResourceUtils {
|
|||
* @return whether the location qualifies as a URL
|
||||
* @see #CLASSPATH_URL_PREFIX
|
||||
* @see java.net.URL
|
||||
* @see #toURL(String)
|
||||
*/
|
||||
public static boolean isUrl(@Nullable String resourceLocation) {
|
||||
if (resourceLocation == null) {
|
||||
|
|
@ -126,6 +127,7 @@ public abstract class ResourceUtils {
|
|||
* "classpath:" pseudo URL, a "file:" URL, or a plain file path
|
||||
* @return a corresponding URL object
|
||||
* @throws FileNotFoundException if the resource cannot be resolved to a URL
|
||||
* @see #toURL(String)
|
||||
*/
|
||||
public static URL getURL(String resourceLocation) throws FileNotFoundException {
|
||||
Assert.notNull(resourceLocation, "Resource location must not be null");
|
||||
|
|
@ -166,6 +168,7 @@ public abstract class ResourceUtils {
|
|||
* @return a corresponding File object
|
||||
* @throws FileNotFoundException if the resource cannot be resolved to
|
||||
* a file in the file system
|
||||
* @see #getFile(URL)
|
||||
*/
|
||||
public static File getFile(String resourceLocation) throws FileNotFoundException {
|
||||
Assert.notNull(resourceLocation, "Resource location must not be null");
|
||||
|
|
@ -197,6 +200,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
|
||||
* @see #getFile(URL, String)
|
||||
*/
|
||||
public static File getFile(URL resourceUrl) throws FileNotFoundException {
|
||||
return getFile(resourceUrl, "URL");
|
||||
|
|
@ -237,6 +241,7 @@ public abstract class ResourceUtils {
|
|||
* @throws FileNotFoundException if the URL cannot be resolved to
|
||||
* a file in the file system
|
||||
* @since 2.5
|
||||
* @see #getFile(URI, String)
|
||||
*/
|
||||
public static File getFile(URI resourceUri) throws FileNotFoundException {
|
||||
return getFile(resourceUri, "URI");
|
||||
|
|
@ -268,6 +273,7 @@ public abstract class ResourceUtils {
|
|||
* i.e. has protocol "file", "vfsfile" or "vfs".
|
||||
* @param url the URL to check
|
||||
* @return whether the URL has been identified as a file system URL
|
||||
* @see #isJarURL(URL)
|
||||
*/
|
||||
public static boolean isFileURL(URL url) {
|
||||
String protocol = url.getProtocol();
|
||||
|
|
@ -281,6 +287,7 @@ public abstract class ResourceUtils {
|
|||
* "vfszip", or "wsjar".
|
||||
* @param url the URL to check
|
||||
* @return whether the URL has been identified as a JAR URL
|
||||
* @see #isJarFileURL(URL)
|
||||
*/
|
||||
public static boolean isJarURL(URL url) {
|
||||
String protocol = url.getProtocol();
|
||||
|
|
@ -295,6 +302,7 @@ public abstract class ResourceUtils {
|
|||
* @param url the URL to check
|
||||
* @return whether the URL has been identified as a JAR file URL
|
||||
* @since 4.1
|
||||
* @see #extractJarFileURL(URL)
|
||||
*/
|
||||
public static boolean isJarFileURL(URL url) {
|
||||
return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
|
||||
|
|
@ -307,6 +315,7 @@ public abstract class ResourceUtils {
|
|||
* @param jarUrl the original URL
|
||||
* @return the URL for the actual jar file
|
||||
* @throws MalformedURLException if no valid jar file URL could be extracted
|
||||
* @see #extractArchiveURL(URL)
|
||||
*/
|
||||
public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
|
||||
String urlFile = jarUrl.getFile();
|
||||
|
|
@ -368,6 +377,7 @@ public abstract class ResourceUtils {
|
|||
* @return the URI instance
|
||||
* @throws URISyntaxException if the URL wasn't a valid URI
|
||||
* @see java.net.URL#toURI()
|
||||
* @see #toURI(String)
|
||||
*/
|
||||
public static URI toURI(URL url) throws URISyntaxException {
|
||||
return toURI(url.toString());
|
||||
|
|
@ -379,18 +389,21 @@ public abstract class ResourceUtils {
|
|||
* @param location the location String to convert into a URI instance
|
||||
* @return the URI instance
|
||||
* @throws URISyntaxException if the location wasn't a valid URI
|
||||
* @see #toURI(URL)
|
||||
*/
|
||||
public static URI toURI(String location) throws URISyntaxException {
|
||||
return new URI(StringUtils.replace(location, " ", "%20"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a URL instance for the given location String,
|
||||
* Create a clean URL instance for the given location String,
|
||||
* going through URI construction and then URL conversion.
|
||||
* @param location the location String to convert into a URL instance
|
||||
* @return the URL instance
|
||||
* @throws MalformedURLException if the location wasn't a valid URL
|
||||
* @since 6.0
|
||||
* @see java.net.URI#toURL()
|
||||
* @see #toURI(String)
|
||||
*/
|
||||
@SuppressWarnings("deprecation") // on JDK 20
|
||||
public static URL toURL(String location) throws MalformedURLException {
|
||||
|
|
@ -406,13 +419,15 @@ public abstract class ResourceUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a URL instance for the given root URL and relative path,
|
||||
* Create a clean URL instance for the given root URL and relative path,
|
||||
* going through URI construction and then URL conversion.
|
||||
* @param root the root URL to start from
|
||||
* @param relativePath the relative path to apply
|
||||
* @return the relative URL instance
|
||||
* @throws MalformedURLException if the end result is not a valid URL
|
||||
* @since 6.0
|
||||
* @see #toURL(String)
|
||||
* @see StringUtils#applyRelativePath
|
||||
*/
|
||||
public static URL toRelativeURL(URL root, String relativePath) throws MalformedURLException {
|
||||
// # can appear in filenames, java.net.URL should not treat it as a fragment
|
||||
|
|
@ -426,6 +441,7 @@ public abstract class ResourceUtils {
|
|||
* given connection, preferring {@code false} but leaving the flag at
|
||||
* its JVM default value for jar resources (typically {@code true}).
|
||||
* @param con the URLConnection to set the flag on
|
||||
* @see URLConnection#setUseCaches
|
||||
*/
|
||||
public static void useCachesIfNecessary(URLConnection con) {
|
||||
if (!(con instanceof JarURLConnection)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue