org.springframework.util
Class ResourceUtils

java.lang.Object
  extended byorg.springframework.util.ResourceUtils

public abstract class ResourceUtils
extends Object

Utility methods for resolving resource locations to files in the file system. Mainly for internal use within the framework.

Consider using Spring's Resource abstraction in the core package for handling all kinds of file resources in a uniform manner. ResourceLoader's getLocation can resolve any location to a Resource object, which in turn allows to get a java.io.File in the file system through its getFile method.

The main reason for these utility methods for resource location handling is to support Log4jConfigurer, which must be able to resolve resource locations before the logging system has been initialized. Spring' Resource abstraction in the core package, on the other hand, already expects the logging system to be available.

Since:
1.1.5
Author:
Juergen Hoeller
See Also:
Resource, ClassPathResource, FileSystemResource, UrlResource, ResourceLoader

Field Summary
static String CLASSPATH_URL_PREFIX
          Pseudo URL prefix for loading from the class path: "classpath:"
static String URL_PROTOCOL_FILE
          URL protocol for a file in the file system: "file"
 
Constructor Summary
ResourceUtils()
           
 
Method Summary
static File getFile(String resourceLocation)
          Resolve the given resource location to a java.io.File, i.e. to a file in the file system.
static File getFile(URL resourceUrl)
          Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
static File getFile(URL resourceUrl, String description)
          Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.
static URL getURL(String resourceLocation)
          Resolve the given resource location to a java.io.File, i.e. to a file in the file system.
static boolean isUrl(String resourceLocation)
          Return whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSPATH_URL_PREFIX

public static final String CLASSPATH_URL_PREFIX
Pseudo URL prefix for loading from the class path: "classpath:"

See Also:
Constant Field Values

URL_PROTOCOL_FILE

public static final String URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file"

See Also:
Constant Field Values
Constructor Detail

ResourceUtils

public ResourceUtils()
Method Detail

isUrl

public static boolean isUrl(String resourceLocation)
Return whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.

See Also:
CLASSPATH_URL_PREFIX, URL

getURL

public static URL getURL(String resourceLocation)
                  throws FileNotFoundException
Resolve the given resource location to a java.io.File, i.e. to a file in the file system.

Does not check whether the file actually exists; simply returns the File that the given location would correspond to.

Parameters:
resourceLocation - the resource location to resolve: either a "classpath:" pseudo URL, a "file:" URL, or a plain file path
Returns:
a corresponding File object
Throws:
FileNotFoundException - if the resource cannot be resolved to a file in the file system

getFile

public static File getFile(String resourceLocation)
                    throws FileNotFoundException
Resolve the given resource location to a java.io.File, i.e. to a file in the file system.

Does not check whether the fil actually exists; simply returns the File that the given location would correspond to.

Parameters:
resourceLocation - the resource location to resolve: either a "classpath:" pseudo URL, a "file:" URL, or a plain file path
Returns:
a corresponding File object
Throws:
FileNotFoundException - if the resource cannot be resolved to a file in the file system

getFile

public static File getFile(URL resourceUrl)
                    throws FileNotFoundException
Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.

Parameters:
resourceUrl - the resource URL to resolve
Returns:
a corresponding File object
Throws:
FileNotFoundException - if the URL cannot be resolved to a file in the file system

getFile

public static File getFile(URL resourceUrl,
                           String description)
                    throws FileNotFoundException
Resolve the given resource URL to a java.io.File, i.e. to a file in the file system.

Parameters:
resourceUrl - the resource URL to resolve
description - a description of the original resource that the URL was created for (for example, a class path location)
Returns:
a corresponding File object
Throws:
FileNotFoundException - if the URL cannot be resolved to a file in the file system


Copyright (C) 2003-2004 The Spring Framework Project.