Package com.aspectran.core.util
Class ResourceUtils
- java.lang.Object
-
- com.aspectran.core.util.ResourceUtils
-
public class ResourceUtils extends java.lang.ObjectA class to simplify access to ResourceUtils through the classloader.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASSPATH_URL_PREFIXstatic java.lang.StringFILE_URL_PREFIXstatic java.lang.StringJAR_FILE_SUFFIXstatic java.lang.StringJAR_URL_PREFIXstatic java.lang.StringJAR_URL_SEPARATORstatic java.lang.StringREGULAR_FILE_SEPARATORstatic charREGULAR_FILE_SEPARATOR_CHARstatic java.lang.StringURL_PROTOCOL_CODE_SOURCEstatic java.lang.StringURL_PROTOCOL_FILEstatic java.lang.StringURL_PROTOCOL_JARstatic java.lang.StringURL_PROTOCOL_VFSZIPstatic java.lang.StringURL_PROTOCOL_WSJARstatic java.lang.StringURL_PROTOCOL_ZIPstatic java.lang.StringZIP_FILE_SUFFIX
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.net.URLextractJarFileURL(java.net.URL jarUrl)static java.io.FilegetFile(java.lang.String resourceLocation)static java.io.FilegetFile(java.lang.String resourceLocation, java.lang.ClassLoader classLoader)static java.io.FilegetFile(java.net.URI resourceUri)static java.io.FilegetFile(java.net.URI resourceUri, java.lang.String description)static java.io.FilegetFile(java.net.URL resourceUrl)static java.io.FilegetFile(java.net.URL resourceUrl, java.lang.String description)static java.io.ReadergetReader(java.io.File file, java.lang.String encoding)Returns a Reader for reading the specified file.static java.io.ReadergetReader(java.net.URL url, java.lang.String encoding)Returns a Reader for reading the specified url.static java.net.URLgetResource(java.lang.String resource)Returns the URL of the resource on the classpath.static java.net.URLgetResource(java.lang.String resource, java.lang.ClassLoader classLoader)Returns the URL of the resource on the classpath.static java.io.FilegetResourceAsFile(java.lang.String resource)static java.io.FilegetResourceAsFile(java.lang.String resource, java.lang.ClassLoader classLoader)static java.io.InputStreamgetResourceAsStream(java.lang.String resource)Returns a resource on the classpath as a Stream object.static java.io.InputStreamgetResourceAsStream(java.lang.String resource, java.lang.ClassLoader classLoader)Returns a resource on the classpath as a Stream object.static java.net.URLgetURL(java.lang.String resourceLocation)static java.net.URLgetURL(java.lang.String resourceLocation, java.lang.ClassLoader classLoader)static booleanisJarSimilarURL(java.net.URL url)static booleanisJarURL(java.net.URL url)static booleanisUrl(java.lang.String resourceLocation)static java.lang.Stringread(java.io.File file, java.lang.String encoding)Returns a string from the specified file.static java.lang.Stringread(java.io.Reader reader)Returns a string from the specified Reader object.static java.lang.Stringread(java.net.URL url, java.lang.String encoding)Returns a string from the specified url.static java.net.URItoURI(java.lang.String location)static java.net.URItoURI(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) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
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) 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.IOExceptionReturns the URL of the resource on the classpath.- Parameters:
resource- the resource to find- Returns:
URLobject for reading the resource;nullif 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.IOExceptionReturns the URL of the resource on the classpath.- Parameters:
classLoader- the class loader used to load the resourceresource- the resource to find- Returns:
URLobject for reading the resource;nullif 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.IOExceptionReturns a resource on the classpath as a Stream object.- Parameters:
resource- the resource to find- Returns:
- an input stream for reading the resource;
nullif 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.IOExceptionReturns 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;
nullif 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.IOExceptionReturns 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.IOExceptionReturns 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.IOExceptionReturns 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.IOExceptionReturns 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.IOExceptionReturns 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
-
-