Java Properties 핸들링 클래스

Java Properties 핸들링 클래스


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.inicis.properties.Properties;

public final class Properties {
private static Log log = LogFactory.getLog(Properties.class);
private static final String PROPERTIES_PATH = ".properties";
private static final String PROPERTIES_SEPERATOR = "|";
private static Properties prop;
private static Properties instance;

private Properties() {
prop = new Properties();
try {
prop.load(getClass().getClassLoader().getResourceAsStream(
PROPERTIES_PATH));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}

/**
* properties 싱글톤
*
* @return
*/
public static Properties getProperties() {
getInstance();
return prop;
}

public static Properties getInstance() {
if (instance == null) {
log.debug(PROPERTIES_PATH + " load...");
instance = new Properties();
}
return instance;
}

/**
* property
*
* @param key
*
* @return
* @throws Exception
*/
public static String getProperty(String key) {
return getProperties().getProperty(key);
}

/**
* property
*
* @param key
*
* @param defaultValue
*
* @return
* @throws Exception
*/
public static String getProperty(String key, String defaultValue) {
return getProperties().getProperty(key, defaultValue);
}

/**
* property
*
* @param key
*
* @return
* @throws Exception
*/
public static String[] getPropertyList(String key) {
return StringUtils.split(getProperties().getProperty(key),
PROPERTIES_SEPERATOR);
}
}
Share