-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilePropertyDataLoader.java
More file actions
55 lines (42 loc) · 1.39 KB
/
FilePropertyDataLoader.java
File metadata and controls
55 lines (42 loc) · 1.39 KB
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
package com.tangoe.components;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
public class FilePropertyDataLoader implements PropertyDataLoader,Runnable {
private volatile Map<String, String> props;
private ScheduledExecutorService es;
private String propertyFilePath;
public FilePropertyDataLoader(String propertyFilePath) {
this.propertyFilePath = propertyFilePath;
}
private void loadData() {
try (BufferedReader reader = new BufferedReader(new FileReader(propertyFilePath))) {
Properties properties = new Properties();
properties.load(reader);
Map<String, String> propMap = new HashMap<>();
properties.forEach((prop, val) -> propMap.put((String) prop, (String) val));
this.props = Collections.unmodifiableMap(propMap);
} catch (IOException ex) {
throw new RuntimeException("Unable to load properties from file", ex);
}
}
@Override
public void startLoading() {
loadData();
}
@Override
public void stopLoading() {
}
@Override
public Map<String, String> getProps() {
return props;
}
@Override
public void run() {
}
}