2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ===================================================================
8 * Modifications Copyright (C) 2019 IBM.
9 * ===================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END============================================
23 package org.onap.champ.util;
26 import java.io.FileInputStream;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.util.Properties;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.champ.service.logging.ChampMsgs;
34 public class ChampProperties {
36 private static Logger logger = LoggerFactory.getInstance().getLogger(ChampProperties.class.getName());
38 private static Properties properties;
41 properties = new Properties();
42 try (FileInputStream fileInputStream = new FileInputStream(
43 new File(ChampServiceConstants.CHAMP_CONFIG_FILE))
45 properties.load(fileInputStream);
46 } catch (IOException e) {
47 logger.error(ChampMsgs.CHAMP_DATA_SERVICE_ERROR, "Error while loading properties ", e.getMessage());
48 Runtime.getRuntime().halt(1);
52 public static String get(String key) {
53 return properties.getProperty(key);
56 public static String get(String key, String defaultValue) {
57 return properties.getProperty(key, defaultValue);
60 public static void put(String key, String value) {
61 properties.setProperty(key, value);
62 try (FileOutputStream fileOut = new FileOutputStream(
63 new File(ChampServiceConstants.CHAMP_CONFIG_FILE))
65 properties.store(fileOut, "Added property: " + key);
66 } catch (Exception e) {
67 logger.error(ChampMsgs.CHAMP_DATA_SERVICE_ERROR, "Error while setting properties ", e.getMessage());