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
- Author:
- Pascal Essiembre
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ReadergetHtmlReader(Class<?> clazz)Gets a UTF-8 reader from resource matching class name with ".html" suffix.static InputStreamgetHtmlStream(Class<?> clazz)Gets a stream from a resource matching class name with ".html" suffix.static StringgetHtmlString(Class<?> clazz)Gets a UTF-8 string from resource matching class name with ".html" suffix.static ReadergetJsonReader(Class<?> clazz)Gets a UTF-8 reader from resource matching class name with ".json" suffix.static InputStreamgetJsonStream(Class<?> clazz)Gets a stream from a resource matching class name with ".json" suffix.static StringgetJsonString(Class<?> clazz)Gets a UTF-8 string from resource matching class name with ".json" suffix.static ReadergetReader(Class<?> clazz, String suffix)Gets a UTF-8 resource from class loader as a reader.static InputStreamgetStream(Class<?> clazz, String suffix)Gets a resource from class loader as stream.static StringgetString(Class<?> clazz, String suffix)Gets a UTF-8 a resource from class loader as a string.static ReadergetTxtReader(Class<?> clazz)Gets a UTF-8 reader from resource matching class name with ".txt" suffix.static InputStreamgetTxtStream(Class<?> clazz)Gets a stream from a resource matching class name with ".txt" suffix.static StringgetTxtString(Class<?> clazz)Gets a UTF-8 string from resource matching class name with ".txt" suffix.static ReadergetXmlReader(Class<?> clazz)Gets a UTF-8 reader from resource matching class name with ".xml" suffix.static InputStreamgetXmlStream(Class<?> clazz)Gets a stream from a resource matching class name with ".xml" suffix.static StringgetXmlString(Class<?> clazz)Gets a UTF-8 string from resource matching class name with ".xml" suffix.
-
-
-
Field Detail
-
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 Detail
-
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 resourcesuffix- the suffix of the file to load with the same name as class- Returns:
- input stream or
nullif class isnullor 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 resourcesuffix- the suffix of the file to load with the same name as class- Returns:
- reader or
nullif class isnullor 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 resourcesuffix- the suffix of the file to load with the same name as class- Returns:
- string or
nullif class isnullor 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
-
-