Package com.aspectran.core.util
Class ResourceUtils
- java.lang.Object
-
- com.aspectran.core.util.ResourceUtils
-
public class ResourceUtils extends java.lang.Object
A class to simplify access to ResourceUtils through the classloader.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLASSPATH_URL_PREFIX
static java.lang.String
FILE_URL_PREFIX
static java.lang.String
JAR_FILE_SUFFIX
static java.lang.String
JAR_URL_PREFIX
static java.lang.String
JAR_URL_SEPARATOR
static java.lang.String
REGULAR_FILE_SEPARATOR
static char
REGULAR_FILE_SEPARATOR_CHAR
static java.lang.String
URL_PROTOCOL_CODE_SOURCE
static java.lang.String
URL_PROTOCOL_FILE
static java.lang.String
URL_PROTOCOL_JAR
static java.lang.String
URL_PROTOCOL_VFSZIP
static java.lang.String
URL_PROTOCOL_WSJAR
static java.lang.String
URL_PROTOCOL_ZIP
static java.lang.String
ZIP_FILE_SUFFIX
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.net.URL
extractJarFileURL(java.net.URL jarUrl)
static java.io.File
getFile(java.lang.String resourceLocation, java.lang.ClassLoader classLoader)
static java.io.File
getFile(java.net.URI resourceUri)
static java.io.File
getFile(java.net.URI resourceUri, java.lang.String description)
static java.io.File
getFile(java.net.URL resourceUrl)
static java.io.File
getFile(java.net.URL resourceUrl, java.lang.String description)
static java.io.Reader
getReader(java.io.File file, java.lang.String encoding)
Returns a Reader for reading the specified file.static java.io.Reader
getReader(java.net.URL url, java.lang.String encoding)
Returns a Reader for reading the specified url.static java.net.URL
getResource(java.lang.String resource)
Returns the URL of the resource on the classpath.static java.net.URL
getResource(java.lang.String resource, java.lang.ClassLoader classLoader)
Returns the URL of the resource on the classpath.static java.io.File
getResourceAsFile(java.lang.String resource)
static java.io.File
getResourceAsFile(java.lang.String resource, java.lang.ClassLoader classLoader)
static java.io.InputStream
getResourceAsStream(java.lang.String resource)
Returns a resource on the classpath as a Stream object.static java.io.InputStream
getResourceAsStream(java.lang.String resource, java.lang.ClassLoader classLoader)
Returns a resource on the classpath as a Stream object.static java.net.URL
getURL(java.lang.String resourceLocation, java.lang.ClassLoader classLoader)
static boolean
isJarSimilarURL(java.net.URL url)
static boolean
isJarURL(java.net.URL url)
static boolean
isUrl(java.lang.String resourceLocation)
static java.lang.String
read(java.io.File file, java.lang.String encoding)
Returns a string from the specified file.static java.lang.String
read(java.io.Reader reader)
Returns a string from the specified Reader object.static java.lang.String
read(java.net.URL url, java.lang.String encoding)
Returns a string from the specified url.static java.net.URI
toURI(java.lang.String location)
static java.net.URI
toURI(java.net.URL url)
-
-
-
Field Detail
-
CLASSPATH_URL_PREFIX
public static final java.lang.String CLASSPATH_URL_PREFIX
- See Also:
- Constant Field Values
-
FILE_URL_PREFIX
public static final java.lang.String FILE_URL_PREFIX
- See Also:
- Constant Field Values
-
JAR_URL_PREFIX
public static final java.lang.String JAR_URL_PREFIX
- See Also:
- Constant Field Values
-
JAR_FILE_SUFFIX
public static final java.lang.String JAR_FILE_SUFFIX
- See Also:
- Constant Field Values
-
ZIP_FILE_SUFFIX
public static final java.lang.String ZIP_FILE_SUFFIX
- See Also:
- Constant Field Values
-
URL_PROTOCOL_FILE
public static final java.lang.String URL_PROTOCOL_FILE
- See Also:
- Constant Field Values
-
URL_PROTOCOL_JAR
public static final java.lang.String URL_PROTOCOL_JAR
- See Also:
- Constant Field Values
-
URL_PROTOCOL_ZIP
public static final java.lang.String URL_PROTOCOL_ZIP
- See Also:
- Constant Field Values
-
URL_PROTOCOL_VFSZIP
public static final java.lang.String URL_PROTOCOL_VFSZIP
- See Also:
- Constant Field Values
-
URL_PROTOCOL_WSJAR
public static final java.lang.String URL_PROTOCOL_WSJAR
- See Also:
- Constant Field Values
-
URL_PROTOCOL_CODE_SOURCE
public static final java.lang.String URL_PROTOCOL_CODE_SOURCE
- See Also:
- Constant Field Values
-
JAR_URL_SEPARATOR
public static final java.lang.String JAR_URL_SEPARATOR
- See Also:
- Constant Field Values
-
REGULAR_FILE_SEPARATOR
public static final java.lang.String REGULAR_FILE_SEPARATOR
- See Also:
- Constant Field Values
-
REGULAR_FILE_SEPARATOR_CHAR
public static final char REGULAR_FILE_SEPARATOR_CHAR
- See Also:
- Constant Field Values
-
-
Method Detail
-
isUrl
public static boolean isUrl(java.lang.String resourceLocation)
-
getURL
public static java.net.URL getURL(java.lang.String resourceLocation, java.lang.ClassLoader classLoader) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getFile
public static java.io.File getFile(java.lang.String resourceLocation, java.lang.ClassLoader classLoader) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getFile
public static java.io.File getFile(java.net.URL resourceUrl) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getFile
public static java.io.File getFile(java.net.URL resourceUrl, java.lang.String description) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getFile
public static java.io.File getFile(java.net.URI resourceUri) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getFile
public static java.io.File getFile(java.net.URI resourceUri, java.lang.String description) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
isJarURL
public static boolean isJarURL(java.net.URL url)
-
isJarSimilarURL
public static boolean isJarSimilarURL(java.net.URL url)
-
extractJarFileURL
public static java.net.URL extractJarFileURL(java.net.URL jarUrl) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
toURI
public static java.net.URI toURI(java.net.URL url) throws java.net.URISyntaxException
- Throws:
java.net.URISyntaxException
-
toURI
public static java.net.URI toURI(java.lang.String location) throws java.net.URISyntaxException
- Throws:
java.net.URISyntaxException
-
getResource
public static java.net.URL getResource(java.lang.String resource) throws java.io.IOException
Returns the URL of the resource on the classpath.- Parameters:
resource
- the resource to find- Returns:
URL
object for reading the resource;null
if the resource could not be found- Throws:
java.io.IOException
- if the resource cannot be found or read
-
getResource
public static java.net.URL getResource(java.lang.String resource, java.lang.ClassLoader classLoader) throws java.io.IOException
Returns the URL of the resource on the classpath.- Parameters:
classLoader
- the class loader used to load the resourceresource
- the resource to find- Returns:
URL
object for reading the resource;null
if the resource could not be found- Throws:
java.io.IOException
- if the resource cannot be found or read
-
getResourceAsFile
public static java.io.File getResourceAsFile(java.lang.String resource) throws java.io.IOException
- Throws:
java.io.IOException
-
getResourceAsFile
public static java.io.File getResourceAsFile(java.lang.String resource, java.lang.ClassLoader classLoader) throws java.io.IOException
- Throws:
java.io.IOException
-
getResourceAsStream
public static java.io.InputStream getResourceAsStream(java.lang.String resource) throws java.io.IOException
Returns a resource on the classpath as a Stream object.- Parameters:
resource
- the resource to find- Returns:
- an input stream for reading the resource;
null
if the resource could not be found - Throws:
java.io.IOException
- if the resource cannot be found or read
-
getResourceAsStream
public static java.io.InputStream getResourceAsStream(java.lang.String resource, java.lang.ClassLoader classLoader) throws java.io.IOException
Returns a resource on the classpath as a Stream object.- Parameters:
resource
- the resource to findclassLoader
- the class loader- Returns:
- an input stream for reading the resource;
null
if the resource could not be found - Throws:
java.io.IOException
- if the resource cannot be found or read
-
getReader
public static java.io.Reader getReader(java.io.File file, java.lang.String encoding) throws java.io.IOException
Returns a Reader for reading the specified file.- Parameters:
file
- the fileencoding
- the encoding- Returns:
- the reader instance
- Throws:
java.io.IOException
- if an error occurred when reading resources using any I/O operations
-
getReader
public static java.io.Reader getReader(java.net.URL url, java.lang.String encoding) throws java.io.IOException
Returns a Reader for reading the specified url.- Parameters:
url
- the urlencoding
- the encoding- Returns:
- the reader instance
- Throws:
java.io.IOException
- if an error occurred when reading resources using any I/O operations
-
read
public static java.lang.String read(java.io.File file, java.lang.String encoding) throws java.io.IOException
Returns a string from the specified file.- Parameters:
file
- the fileencoding
- the encoding- Returns:
- the reader instance
- Throws:
java.io.IOException
- if an error occurred when reading resources using any I/O operations
-
read
public static java.lang.String read(java.net.URL url, java.lang.String encoding) throws java.io.IOException
Returns a string from the specified url.- Parameters:
url
- the urlencoding
- the encoding- Returns:
- the string
- Throws:
java.io.IOException
- if an error occurred when reading resources using any I/O operations
-
read
public static java.lang.String read(java.io.Reader reader) throws java.io.IOException
Returns a string from the specified Reader object.- Parameters:
reader
- the reader- Returns:
- the string
- Throws:
java.io.IOException
- if an error occurred when reading resources using any I/O operations
-
-