Module watamebot

Class ResourceUtils

java.lang.Object
net.foxgenesis.util.ResourceUtils

public final class ResourceUtils extends Object
NEED_JAVADOC
Author:
Ashley
  • Constructor Details

    • ResourceUtils

      public ResourceUtils()
  • Method Details

    • linesFromResource

      public static List<String> linesFromResource(URL path) throws IOException
      Read all lines from a resource
      Parameters:
      path - - URL path to the resource
      Returns:
      Returns all lines as a List<String>
      Throws:
      IOException - Thrown if an error occurs while reading the InputStream of the resource
    • getProperties

      public static Properties getProperties(URL path) throws IOException
      NEED_JAVADOC
      Parameters:
      path -
      Returns:
      Throws:
      IOException
    • getProperties

      public static Properties getProperties(Path path, ModuleResource defaults) throws IOException
      Parse a Properties file at the specified Path. If the specified file was not found, the defaults will be written to its location.
      Parameters:
      path - - path to the properties file
      defaults - - (optional) resource containing the default properties file
      Returns:
      Returns a Properties file that was parsed from the specified path
      Throws:
      IOException - If an I/O error occurs
      FileNotFoundException - If the specified file was not found and no defaults were given
    • loadProperties

      public static org.apache.commons.configuration2.PropertiesConfiguration loadProperties(ModuleResource defaults, Path dir, String output) throws IOException, org.apache.commons.configuration2.ex.ConfigurationException
      NEED_JAVADOC
      Parameters:
      defaults -
      dir -
      output -
      Returns:
      Throws:
      IOException
      org.apache.commons.configuration2.ex.ConfigurationException
    • loadINI

      public static org.apache.commons.configuration2.INIConfiguration loadINI(ModuleResource defaults, Path dir, String output) throws IOException, org.apache.commons.configuration2.ex.ConfigurationException
      Load an .ini configuration file from the specified directory and file. If the file is not found, the provided ModuleResource pointing to the configuration defaults will be used instead.
      Parameters:
      defaults - - resource containing the configuration defaults
      dir - - the directory containing the configuration file
      output - - the name of the configuration file
      Returns:
      Returns the parsed INIConfiguration
      Throws:
      IOException - If an I/O error occurs
      org.apache.commons.configuration2.ex.ConfigurationException - If an error occurs
      SecurityException - Thrown if the specified file is not readable
    • toString

      public static String toString(@Nonnull InputStream input) throws IOException
      Read all data from the specified InputStream and parse it as a string.

      The input stream will be closed after completion

      Parameters:
      input - - the input stream to read
      Returns:
      Returns a string containing the data from the specified input stream
      Throws:
      IOException - If an I/O error occurs
    • toSplitString

      public static String[] toSplitString(@Nonnull InputStream input) throws IOException
      Read all data from the specified InputStream and parse all lines as a string array.

      The input stream will be closed after completion

      This method is effectively equivalent to:

       toString(input).split("(\\r\\n|\\r|\\n)")
       
      Parameters:
      input - - the input stream to read
      Returns:
      Returns a string array containing the data from the specified input stream
      Throws:
      IOException - If an I/O error occurs