b029dd1352e331390cd2279f95e40a33475d3264
[aai/gizmo.git] / src / main / java / org / onap / crud / util / CrudProperties.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Gizmo
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.crud.util;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.util.Properties;
32
33 public class CrudProperties {
34
35   private static Properties properties;
36
37   static {
38     properties = new Properties();
39     File file = new File(CrudServiceConstants.CRD_CONFIG_FILE);
40     try {
41       properties.load(new FileInputStream(file));
42     } catch (FileNotFoundException e) {
43       e.printStackTrace();
44     } catch (IOException e) {
45       e.printStackTrace();
46     }
47   }
48
49   public static String get(String key) {
50     return properties.getProperty(key);
51   }
52
53   public static String get(String key, String defaultValue) {
54     return properties.getProperty(key, defaultValue);
55   }
56
57   public static void put(String key, String value) {
58     properties.setProperty(key, value);
59     FileOutputStream fileOut = null;
60     try {
61       fileOut = new FileOutputStream(new File(CrudServiceConstants.CRD_CONFIG_FILE));
62       properties.store(fileOut, "Added property: " + key);
63     } catch (Exception e) {
64       e.printStackTrace();
65     } finally {
66
67       try {
68         fileOut.close();
69       } catch (IOException ex) {
70         ex.printStackTrace();
71       }
72     }
73
74   }
75
76
77 }