Package com.norconex.commons.lang

# Class ResourceLoader

java.lang.Object
com.norconex.commons.lang.ResourceLoader

public final class ResourceLoader extends Object
Utility class for loading resource from class loader, relative to a given class.

Since:
  1.14.0

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `HTML`
  `static final String`
  `JSON`
  `static final String`
  `TXT`
  `static final String`
  `XML`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Reader`
  `getHtmlReader(Class<?> clazz)`
  Gets a UTF-8 reader from resource matching class name with ".html" suffix.
  `static InputStream`
  `getHtmlStream(Class<?> clazz)`
  Gets a stream from a resource matching class name with ".html" suffix.
  `static String`
  `getHtmlString(Class<?> clazz)`
  Gets a UTF-8 string from resource matching class name with ".html" suffix.
  `static Reader`
  `getJsonReader(Class<?> clazz)`
  Gets a UTF-8 reader from resource matching class name with ".json" suffix.
  `static InputStream`
  `getJsonStream(Class<?> clazz)`
  Gets a stream from a resource matching class name with ".json" suffix.
  `static String`
  `getJsonString(Class<?> clazz)`
  Gets a UTF-8 string from resource matching class name with ".json" suffix.
  `static Reader`
  `getReader(Class<?> clazz, String suffix)`
  Gets a UTF-8 resource from class loader as a reader.
  `static InputStream`
  `getStream(Class<?> clazz, String suffix)`
  Gets a resource from class loader as stream.
  `static String`
  `getString(Class<?> clazz, String suffix)`
  Gets a UTF-8 a resource from class loader as a string.
  `static Reader`
  `getTxtReader(Class<?> clazz)`
  Gets a UTF-8 reader from resource matching class name with ".txt" suffix.
  `static InputStream`
  `getTxtStream(Class<?> clazz)`
  Gets a stream from a resource matching class name with ".txt" suffix.
  `static String`
  `getTxtString(Class<?> clazz)`
  Gets a UTF-8 string from resource matching class name with ".txt" suffix.
  `static Reader`
  `getXmlReader(Class<?> clazz)`
  Gets a UTF-8 reader from resource matching class name with ".xml" suffix.
  `static InputStream`
  `getXmlStream(Class<?> clazz)`
  Gets a stream from a resource matching class name with ".xml" suffix.
  `static String`
  `getXmlString(Class<?> clazz)`
  Gets a UTF-8 string from resource matching class name with ".xml" suffix.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### TXT

    public static final String TXT
    Since:
      2.0.0
    See Also:
      - Constant Field Values

  - ### HTML

    public static final String HTML
    Since:
      2.0.0
    See Also:
      - Constant Field Values

  - ### XML

    public static final String XML
    Since:
      2.0.0
    See Also:
      - Constant Field Values

  - ### JSON

    public static final String JSON
    Since:
      2.0.0
    See Also:
      - Constant Field Values

- ## Method Details

  - ### getStream

    public static InputStream getStream(Class<?> clazz, String suffix)
    Gets a resource from class loader as stream. The resource is relative to the given class, with the same name as the class, but with the supplied suffix.
    Parameters:
      `clazz` - the class to load related resource
      `suffix` - the suffix of the file to load with the same name as class
    Returns:
      input stream or `null` if class is `null` or resource could not be found.

  - ### getReader

    public static Reader getReader(Class<?> clazz, String suffix)
    Gets a UTF-8 resource from class loader as a reader. The resource is relative to the given class, with the same name as the class, but with the supplied suffix.
    Parameters:
      `clazz` - the class to load related resource
      `suffix` - the suffix of the file to load with the same name as class
    Returns:
      reader or `null` if class is `null` or resource could not be found.

  - ### getString

    public static String getString(Class<?> clazz, String suffix)
    Gets a UTF-8 a resource from class loader as a string. The resource is relative to the given class, with the same name as the class, but with the supplied suffix.
    Parameters:
      `clazz` - the class to load related resource
      `suffix` - the suffix of the file to load with the same name as class
    Returns:
      string or `null` if class is `null` or resource could not be found.

  - ### getXmlStream

    public static InputStream getXmlStream(Class<?> clazz)
    Gets a stream from a resource matching class name with ".xml" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      XML stream or `null`

  - ### getXmlReader

    public static Reader getXmlReader(Class<?> clazz)
    Gets a UTF-8 reader from resource matching class name with ".xml" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      XML reader or `null`

  - ### getXmlString

    public static String getXmlString(Class<?> clazz)
    Gets a UTF-8 string from resource matching class name with ".xml" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      XML string or `null`

  - ### getTxtStream

    public static InputStream getTxtStream(Class<?> clazz)
    Gets a stream from a resource matching class name with ".txt" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      text stream or `null`

  - ### getTxtReader

    public static Reader getTxtReader(Class<?> clazz)
    Gets a UTF-8 reader from resource matching class name with ".txt" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      text reader or `null`

  - ### getTxtString

    public static String getTxtString(Class<?> clazz)
    Gets a UTF-8 string from resource matching class name with ".txt" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      text string or `null`

  - ### getHtmlStream

    public static InputStream getHtmlStream(Class<?> clazz)
    Gets a stream from a resource matching class name with ".html" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      HTML stream or `null`

  - ### getHtmlReader

    public static Reader getHtmlReader(Class<?> clazz)
    Gets a UTF-8 reader from resource matching class name with ".html" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      HTML reader or `null`

  - ### getHtmlString

    public static String getHtmlString(Class<?> clazz)
    Gets a UTF-8 string from resource matching class name with ".html" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      HTML string or `null`

  - ### getJsonStream

    public static InputStream getJsonStream(Class<?> clazz)
    Gets a stream from a resource matching class name with ".json" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      JSON stream or `null`

  - ### getJsonReader

    public static Reader getJsonReader(Class<?> clazz)
    Gets a UTF-8 reader from resource matching class name with ".json" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      JSON reader or `null`

  - ### getJsonString

    public static String getJsonString(Class<?> clazz)
    Gets a UTF-8 string from resource matching class name with ".json" suffix.
    Parameters:
      `clazz` - the class to load related resource
    Returns:
      JSON string or `null`