public static String getPropertyOrDefault ( Class < ? > referenceClass , String propertyFile , String key , String defaultValue ) { try ( InputStream stream = referenceClass . getResourceAsStream ( propertyFile ) ) { if ( stream == null ) { logger . atSevere ( ) . log ( "Could not load properties file '%s'" , propertyFile ) ; return defaultValue ; } Properties properties = new Properties ( ) ; properties . load ( stream ) ; String value = properties . getProperty ( key ) ; if ( value == null ) { logger . atSevere ( ) . log ( "Key %s not found in properties file %s." , key , propertyFile ) ; return defaultValue ; } return value ; } catch ( IOException e ) { logger . atSevere ( ) . withCause ( e ) . log ( "Error while trying to get property value for key %s" , key ) ; return defaultValue ; } }
Get the value of a property or a default value if there s an error retrieving the property key .