Package: org.grails.io.support

## [Java] Class ClassPathResource

- org.grails.io.support.ClassPathResource

-     public class ClassPathResource
      extends AbstractFileResolvingResource

  Resource implementation for class path resources. Uses either a given ClassLoader or a given Class for loading resources.

  Supports resolution as `java.io.File` if the class path resource resides in the file system, but not for resources in a JAR. Always supports resolution as URL.

  Authors:
    Juergen Hoeller
  Since:
    28.12.2003
  See Also:
    java.lang.ClassLoader#getResourceAsStream(String)
    java.lang.Class#getResourceAsStream(String)

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `private java.lang.ClassLoader` | `classLoader` |
    `private java.lang.Class<?>` | `clazz` |
    `private java.lang.String` | `path` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ClassPathResource (java.lang.String path)` Create a new ClassPathResource for ClassLoader usage.
    `ClassPathResource (java.lang.String path, java.lang.ClassLoader classLoader)` Create a new ClassPathResource for ClassLoader usage.
    `ClassPathResource (java.lang.String path, java.lang.Class<?> clazz)` Create a new ClassPathResource for Class usage.
    `protected ClassPathResource (java.lang.String path, java.lang.ClassLoader classLoader, java.lang.Class<?> clazz)` Create a new ClassPathResource with optional ClassLoader and Class.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Resource` | `createRelative(java.lang.String relativePath)` This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.
    `` | `public boolean` | `equals(java.lang.Object obj)` This implementation compares the underlying class path locations.
    `` | `public boolean` | `exists()` This implementation checks for the resolution of a resource URL.
    `` | `public final java.lang.ClassLoader` | `getClassLoader()` Return the ClassLoader that this resource will be obtained from.
    `` | `public java.lang.String` | `getDescription()` This implementation returns a description that includes the class path location.
    `` | `public java.lang.String` | `getFilename()` This implementation returns the name of the file that this class path resource refers to.
    `` | `public java.io.InputStream` | `getInputStream()` This implementation opens an InputStream for the given class path resource.
    `` | `public final java.lang.String` | `getPath()` Return the path for this resource (as resource path within the class path).
    `` | `public java.net.URI` | `getURI()`
    `` | `public java.net.URL` | `getURL()` This implementation returns a URL for the underlying class path resource.
    `` | `public int` | `hashCode()` This implementation returns the hash code of the underlying class path location.
    `` | `private static boolean` | `nullSafeEquals(java.lang.Object o1, java.lang.Object o2)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class AbstractFileResolvingResource` | `contentLength, exists, getFile, getFile, getFileForLastModifiedCheck, isReadable, lastModified, useCachesIfNecessary`

- - ### Field Detail

    - #### private java.lang.ClassLoader classLoader

    - #### private java.lang.Class<?> clazz

    - #### private final java.lang.String path

  - ### Constructor Detail

    - #### public ClassPathResource(java.lang.String path)

      Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.

      The thread context class loader will be used for loading the resource.

      Parameters:
        `path` - the absolute path within the class path
      See Also:
        java.lang.ClassLoader#getResourceAsStream(String)

    - #### public ClassPathResource(java.lang.String path, java.lang.ClassLoader classLoader)

      Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.

      Parameters:
        `path` - the absolute path within the classpath
        `classLoader` - the class loader to load the resource with, or `null` for the thread context class loader
      See Also:
        java.lang.ClassLoader#getResourceAsStream(String)

    - #### public ClassPathResource(java.lang.String path, java.lang.Class<?> clazz)

      Create a new ClassPathResource for Class usage. The path can be relative to the given class, or absolute within the classpath via a leading slash.

      Parameters:
        `path` - relative or absolute path within the class path
        `clazz` - the class to load resources with
      See Also:
        java.lang.Class#getResourceAsStream

    - #### protected ClassPathResource(java.lang.String path, java.lang.ClassLoader classLoader, java.lang.Class<?> clazz)

      Create a new ClassPathResource with optional ClassLoader and Class. Only for internal usage.

      Parameters:
        `path` - relative or absolute path within the classpath
        `classLoader` - the class loader to load the resource with, if any
        `clazz` - the class to load resources with, if any

  - ### Method Detail

    - #### public Resource createRelative(java.lang.String relativePath)

      This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.

    - #### @java.lang.Override public boolean equals(java.lang.Object obj)

      This implementation compares the underlying class path locations.

    - #### @java.lang.Override public boolean exists()

      This implementation checks for the resolution of a resource URL.

      See Also:
        java.lang.ClassLoader#getResource(String)
        java.lang.Class#getResource(String)

    - #### public final java.lang.ClassLoader getClassLoader()

      Return the ClassLoader that this resource will be obtained from.

    - #### public java.lang.String getDescription()

      This implementation returns a description that includes the class path location.

    - #### public java.lang.String getFilename()

      This implementation returns the name of the file that this class path resource refers to.

    - #### public java.io.InputStream getInputStream()

      This implementation opens an InputStream for the given class path resource.

      See Also:
        java.lang.ClassLoader#getResourceAsStream(String)
        java.lang.Class#getResourceAsStream(String)

    - #### public final java.lang.String getPath()

      Return the path for this resource (as resource path within the class path).

    - #### public java.net.URI getURI()

    - #### public java.net.URL getURL()

      This implementation returns a URL for the underlying class path resource.

      See Also:
        java.lang.ClassLoader#getResource(String)
        java.lang.Class#getResource(String)

    - #### @java.lang.Override public int hashCode()

      This implementation returns the hash code of the underlying class path location.

    - #### private static boolean nullSafeEquals(java.lang.Object o1, java.lang.Object o2)