View Javadoc
1   package com.jsql.util;
2   
3   import org.apache.logging.log4j.LogManager;
4   import org.apache.logging.log4j.Logger;
5   
6   import java.io.IOException;
7   import java.io.InputStream;
8   import java.util.Properties;
9   
10  public class PropertiesUtil {
11      
12      /**
13       * Log4j logger sent to view.
14       */
15      private static final Logger LOGGER = LogManager.getRootLogger();
16  
17      private final Properties properties = new Properties();
18      
19      public PropertiesUtil() {
20          
21          var filename = "config.properties";
22  
23          try (InputStream input = PropertiesUtil.class.getClassLoader().getResourceAsStream(filename)) {
24              
25              if (input == null) {
26                  
27                  LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Properties file {} not found", filename);
28                  return;
29              }
30  
31              // load a properties file from class path, inside static method
32              this.getProperties().load(input);
33              
34          } catch (IOException e) {
35              LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
36          }
37      }
38  
39      public Properties getProperties() {
40          return this.properties;
41      }
42  }