Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.97 KB | None | 0 0
  1. package com.peekaboo.miscellaneous
  2.  
  3. import java.io.{FileInputStream, InputStream}
  4. import java.util.Properties
  5.  
  6. import org.apache.logging.log4j.LogManager
  7. /**
  8.   * Created by Glowacki on 16.08.2016.
  9.   */
  10. object PropertiesParser {
  11.   /**
  12.     * Get value by key from .properties files
  13.     *
  14.     *  WatsonKey Search Key
  15.     * propertiesPath Have default value
  16.     * @return Value by Search Key
  17.     */
  18.  
  19.   val propertiesPath: String = "src\\main\\resources\\config\\application.properties"
  20.   val logger = LogManager.getLogger(this)
  21.   def getValue(Key: String): String = {
  22.     try {
  23.       val classLoader = Thread.currentThread().getContextClassLoader()
  24.       val input = classLoader.getResourceAsStream("/config/application.properties")
  25.       val prop  = new Properties()
  26.       prop.load (input)
  27.       prop.getProperty(Key)
  28.     }catch { case ex : Exception =>
  29.       logger.error("Error with reading file application.properties "+ex.getMessage)
  30.       null
  31.     }
  32.  
  33.   }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement