• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package com.update.check.action.view;
17 
18 import com.update.check.log.Logger;
19 import org.jetbrains.annotations.NotNull;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.nio.charset.StandardCharsets;
24 import java.util.Properties;
25 
26 /**
27  * ConstString
28  *
29  * @since 23-04-07
30  */
31 public class ConstString {
32     private static final String LOG_TAG = ConstString.class.getName();
33 
34     private static final Logger LOGGER = Logger.createLogger();
35 
36     private static Properties properties = new Properties();
37 
38     /**
39      * load .properties file
40      */
loadProperties()41     public static void loadProperties() {
42         InputStream inputStream = null;
43         try {
44             inputStream = ConstString.class.getClassLoader().getResourceAsStream("const.properties");
45             properties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
46         } catch (IOException e) {
47             LOGGER.error(LOG_TAG, "get const.properties error!");
48         } finally {
49             try {
50                 inputStream.close();
51             } catch (IOException ie) {
52                 LOGGER.error(LOG_TAG, "inputStream close error!");
53             }
54         }
55     }
56 
57     /**
58      * get Fields
59      *
60      * @param key    key
61      * @return field
62      */
get(@otNull String key)63     public static String get(@NotNull String key) {
64         if (properties.size() == 0) {
65             loadProperties();
66         }
67         return properties.getProperty(key);
68     }
69 
70 }
71