Class Resources

java.lang.Object
org.moeaframework.util.io.Resources

public class Resources extends Object
Utilities for working with resources, which are files that are embedded within Java JAR files and discoverable on the classpath.
  • Method Details

    • asStream

      public static InputStream asStream(Class<?> owner, String resource, Resources.ResourceOption... options) throws IOException
      Opens the resource as an InputStream. The caller is expected to close the stream when no longer used.
      Parameters:
      owner - the class that is requesting the resource
      resource - the resource path
      options - 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 a Reader. The caller is expected to close the reader when no longer used.
      Parameters:
      owner - the class that is requesting the resource
      resource - the resource path
      options - 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 a CommentedLineReader. The caller is expected to close the reader when no longer used.
      Parameters:
      owner - the class that is requesting the resource
      resource - the resource path
      options - 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 resource
      resource - the resource path
      options - 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 resource
      resource - the resource path
      options - 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