Config.java

  1. package coneforest.psylla.runtime;

  2. import java.io.IOException;
  3. import java.util.Properties;
  4. import java.util.Set;

  5. /**
  6. *   Methods for obtaining configuration properties stored in the {@code Config.properties} resource.
  7. */
  8. public class Config
  9. {
  10.     private static final Properties CONFIG=new Properties();

  11.     private Config()
  12.     {
  13.     }

  14.     /**
  15.     *   {@return the value associated with the given name} If not found, returns {@code null}.
  16.     *
  17.     *   @param name the property name.
  18.     */
  19.     public static String getProperty(final String name)
  20.     {
  21.         return CONFIG.getProperty(name);
  22.     }

  23.     /**
  24.     *   {@return an unmodifiable set of property names}
  25.     */
  26.     public static Set<String> stringPropertyNames()
  27.     {
  28.         return CONFIG.stringPropertyNames();
  29.     }

  30.     static
  31.     {
  32.         try(final var resourceStream=Config.class.getResourceAsStream("Config.properties"))
  33.         {
  34.             CONFIG.load(resourceStream);
  35.         }
  36.         catch(final IOException ex)
  37.         {
  38.             System.out.println(ex.getMessage());
  39.             System.exit(1);
  40.         }
  41.     }
  42. }