Package org.moeaframework.util.io
Class Resources
java.lang.Object
org.moeaframework.util.io.Resources
Utilities for working with resources, which are files that are embedded within Java JAR files and discoverable on
the classpath.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumOptions used when locating and extracting resources. -
Method Summary
Modifier and TypeMethodDescriptionstatic FileasFile(Class<?> owner, String resource, Resources.ResourceOption... options) Locates the resource as a file on disk, extracting the contents of the resource to a file if required.static LineReaderasLineReader(Class<?> owner, String resource, Resources.ResourceOption... options) Opens the resource as aLineReader.static ReaderasReader(Class<?> owner, String resource, Resources.ResourceOption... options) Opens the resource as aReader.static InputStreamasStream(Class<?> owner, String resource, Resources.ResourceOption... options) Opens the resource as anInputStream.static StringreadString(Class<?> owner, String resource, Resources.ResourceOption... options) Loads the contents of the resource as a string.
-
Method Details
-
asStream
public static InputStream asStream(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException Opens the resource as anInputStream. The caller is expected to close the stream when no longer used.- Parameters:
owner- the class that is requesting the resourceresource- the resource pathoptions- options for locating and opening the resource- Returns:
- the input stream, or
nullif the resource was not found - Throws:
IOException- if an I/O error occurred
-
asReader
public static Reader asReader(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException Opens the resource as aReader. The caller is expected to close the reader when no longer used.- Parameters:
owner- the class that is requesting the resourceresource- the resource pathoptions- options for locating and opening the resource- Returns:
- the reader, or
nullif the resource was not found - Throws:
IOException- if an I/O error occurred
-
asLineReader
public static LineReader asLineReader(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException Opens the resource as aLineReader. The caller is expected to close the reader when no longer used.- Parameters:
owner- the class that is requesting the resourceresource- the resource pathoptions- options for locating and opening the resource- Returns:
- the reader, or
nullif the resource was not found - Throws:
IOException- if an I/O error occurred
-
readString
public static String readString(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException Loads the contents of the resource as a string.- Parameters:
owner- the class that is requesting the resourceresource- the resource pathoptions- options for locating and opening the resource- Returns:
- the contents, or
nullif the resource was not found - Throws:
IOException- if an I/O error occurred
-
asFile
public static File asFile(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException Locates the resource as a file on disk, extracting the contents of the resource to a file if required.- Parameters:
owner- the class that is requesting the resourceresource- the resource pathoptions- options for locating and opening the resource- Returns:
- the contents, or
nullif the resource was not found - Throws:
IOException- if an I/O error occurred
-