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
Modifier and TypeClassDescriptionstatic enum
Options used when locating and extracting resources. -
Method Summary
Modifier and TypeMethodDescriptionstatic File
asFile
(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 CommentedLineReader
asLineReader
(Class<?> owner, String resource, Resources.ResourceOption... options) Opens the resource as aCommentedLineReader
.static Reader
asReader
(Class<?> owner, String resource, Resources.ResourceOption... options) Opens the resource as aReader
.static InputStream
asStream
(Class<?> owner, String resource, Resources.ResourceOption... options) Opens the resource as anInputStream
.static String
readString
(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
null
if 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
null
if the resource was not found - Throws:
IOException
- if an I/O error occurred
-
asLineReader
public static CommentedLineReader asLineReader(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException Opens the resource as aCommentedLineReader
. 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
null
if 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
null
if 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
null
if the resource was not found - Throws:
IOException
- if an I/O error occurred
-