Github user tellison commented on a diff in the pull request: https://github.com/apache/incubator-pirk/pull/27#discussion_r72701970 --- Diff: src/main/java/org/apache/pirk/utils/SystemConfiguration.java --- @@ -160,4 +139,78 @@ public static void resetProperties() clearProperties(); initialize(); } + + /** + * Loads the properties from local properties file in the specified directory + * <p> + * Only files ending in '.properties' will be loaded + */ + public static void loadPropsFromDir(String dirName) + { + File[] directoryListing = new File(dirName).listFiles(new FilenameFilter() + { + @Override + public boolean accept(File dir, String name) + { + return name.endsWith(".properties"); + } + }); + + if (directoryListing != null) + { + for (File file : directoryListing) + { + loadPropsFromFile(file); + } + } + } + + /** + * Loads the properties from the specified file + */ + public static void loadPropsFromFile(File file) + { + if (file.exists()) + { + try (InputStream stream = new FileInputStream(file);) + { + logger.info("Loading properties file '" + file.getAbsolutePath() + "'"); + props.load(stream); + stream.close(); + } catch (IOException e) + { + logger.error("Problem loading properties file '" + file.getAbsolutePath() + "'"); + e.printStackTrace(); + } + } + else + { + logger.warn("Properties file does not exist: '" + file.getAbsolutePath() + "'"); + } + } + + /** + * Loads the properties from the specified file on the classpath + */ + public static void loadPropsFromStream(String name) + { + try + { + InputStream stream = SystemConfiguration.class.getClassLoader().getResourceAsStream(name); + if (stream != null) + { + logger.info("Loading file '" + name + "'"); + props.load(stream); + stream.close(); --- End diff -- Can use try-with-resources to ensure the stream is closed even if the load causes an exception.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---