Class ResourceUtils


  • public class ResourceUtils
    extends Object
    resource util
    Author:
    boyan
    • Constructor Detail

      • ResourceUtils

        public ResourceUtils()
    • Method Detail

      • getResourceURL

        public static URL getResourceURL​(String resource)
                                  throws IOException
        Returns the URL of the resource on the classpath
        Parameters:
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceURL

        public static URL getResourceURL​(ClassLoader loader,
                                         String resource)
                                  throws IOException
        Returns the URL of the resource on the classpath
        Parameters:
        loader - The classloader used to load the resource
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsStream

        public static InputStream getResourceAsStream​(String resource)
                                               throws IOException
        Returns a resource on the classpath as a Stream object
        Parameters:
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsStream

        public static InputStream getResourceAsStream​(ClassLoader loader,
                                                      String resource)
                                               throws IOException
        Returns a resource on the classpath as a Stream object
        Parameters:
        loader - The classloader used to load the resource
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsProperties

        public static Properties getResourceAsProperties​(String resource)
                                                  throws IOException
        Returns a resource on the classpath as a Properties object
        Parameters:
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsProperties

        public static Properties getResourceAsProperties​(ClassLoader loader,
                                                         String resource)
                                                  throws IOException
        Returns a resource on the classpath as a Properties object
        Parameters:
        loader - The classloader used to load the resource
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsReader

        public static InputStreamReader getResourceAsReader​(String resource,
                                                            String charsetName)
                                                     throws IOException
        Returns a resource on the classpath as a Reader object
        Parameters:
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsReader

        public static Reader getResourceAsReader​(ClassLoader loader,
                                                 String resource,
                                                 String charsetName)
                                          throws IOException
        Returns a resource on the classpath as a Reader object
        Parameters:
        loader - The classloader used to load the resource
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsFile

        public static File getResourceAsFile​(String resource)
                                      throws IOException
        Returns a resource on the classpath as a File object
        Parameters:
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read
      • getResourceAsFile

        public static File getResourceAsFile​(URL url)
        Returns a resource on the classpath as a File object
        Parameters:
        url - The resource url to find
        Returns:
        The resource
      • getResourceAsFile

        public static File getResourceAsFile​(ClassLoader loader,
                                             String resource)
                                      throws IOException
        Returns a resource on the classpath as a File object
        Parameters:
        loader - The classloader used to load the resource
        resource - The resource to find
        Returns:
        The resource
        Throws:
        IOException - If the resource cannot be found or read