-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
51 lines (40 loc) · 1.49 KB
/
Config.java
File metadata and controls
51 lines (40 loc) · 1.49 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
package com.urise.webapp;
import com.urise.webapp.storage.SqlStorage;
import com.urise.webapp.storage.Storage;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
public class Config {
protected static final File PROPS = new File(getHomeDir(), "config\\resumes.properties");
private static final Config INSTANCE = new Config();
private final File storageDir;
private final Storage sqlStorage;
public static Config getINSTANCE() {
return INSTANCE;
}
private Config() {
try {
InputStream inputStream = new FileInputStream(PROPS);
Properties props = new Properties();
props.load(inputStream);
storageDir = new File(props.getProperty("storage.dir"));
sqlStorage = new SqlStorage(props.getProperty("db.url"), props.getProperty("db.user"), props.getProperty("db.password"));
} catch (Exception e) {
throw new IllegalStateException("Invalid config file: " + PROPS.getAbsolutePath());
}
}
public File getStorageDir() {
return storageDir;
}
public Storage getSqlStorage() {
return sqlStorage;
}
private static File getHomeDir() {
File homeDir = new File(System.getProperty("homeDir") == null ? "." : System.getProperty("homeDir"));
if (!homeDir.isDirectory()) {
throw new IllegalStateException("Illegal directory: " + homeDir);
}
return homeDir;
}
}