Port champ-microservice project restructure
[aai/champ.git] / champ-service / src / main / java / org / onap / champ / util / ChampProperties.java
1 package org.onap.champ.util;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 import java.util.Properties;
9
10 public class ChampProperties {
11
12   private static Properties properties;
13
14   static {
15     properties = new Properties();
16     File file = new File(ChampServiceConstants.CHAMP_CONFIG_FILE);
17     try {
18       properties.load(new FileInputStream(file));
19     } catch (IOException e) {
20       e.printStackTrace();
21       Runtime.getRuntime().halt(1);
22     }
23   }
24
25   public static String get(String key) {
26     return properties.getProperty(key);
27   }
28
29   public static String get(String key, String defaultValue) {
30     return properties.getProperty(key, defaultValue);
31   }
32
33   public static void put(String key, String value) {
34     properties.setProperty(key, value);
35     FileOutputStream fileOut = null;
36     try {
37       fileOut = new FileOutputStream(new File(ChampServiceConstants.CHAMP_CONFIG_FILE));
38       properties.store(fileOut, "Added property: " + key);
39     } catch (Exception e) {
40       e.printStackTrace();
41     } finally {
42
43       try {
44         fileOut.close();
45       } catch (IOException ex) {
46         ex.printStackTrace();
47       }
48     }
49
50   }
51
52
53 }