2 * Copyright (c) 2018-2019. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.Properties;
24 * ChessHog properties holder.
26 * @author Dmitry Samoshin aka gotty
28 public class ChessHogProperties {
30 /** Properties file. */
31 private static final String PROPERTIES_FILE = "chesshog.properties";
34 private static final Properties PROPERTIES;
37 * Static properties initialization.
40 PROPERTIES = new Properties();
41 readProperties(PROPERTIES_FILE, PROPERTIES, true);
45 * @param propsFile Properties file name.
46 * @param props Properties.
47 * @param throwExc Flag indicating whether to throw an exception or not.
49 public static void readProperties(String propsFile, Properties props, boolean throwExc) {
50 try (InputStream is = ChessHogProperties.class.getClassLoader().getResourceAsStream(propsFile)) {
53 throw new RuntimeException("Failed to find properties file: " + propsFile);
60 catch (IOException e) {
61 throw new RuntimeException("Failed to read properties file: " + propsFile, e);
66 * Empty string for not found properties.
68 private static final String EMPTY = "";
71 * Gets property value.
73 * @param key Property key.
74 * @return Property value (possibly empty string, but never {@code null}).
76 public static String get(String key) {
77 return PROPERTIES.getProperty(key, EMPTY);
81 * Private constructor.
83 private ChessHogProperties() {