forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
48 lines (39 loc) · 1.42 KB
/
Config.java
File metadata and controls
48 lines (39 loc) · 1.42 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
package ru.javaops.webapp;
import ru.javaops.webapp.storage.FileStorage;
import ru.javaops.webapp.storage.IStorage;
import ru.javaops.webapp.storage.SqlStorage;
import java.io.*;
import java.util.Properties;
public class Config {
private final static String PROPS = "/resumes.properties";
private static final Config INSTANCE = new Config();
private final File storageDir;
private final IStorage storage;
public static Config getInstance() {
return INSTANCE;
}
private Config() {
try (InputStream is = Config.class.getResourceAsStream(PROPS)) {
Properties prop = new Properties();
prop.load(is);
storageDir = new File(prop.getProperty("storage.dir"));
storage = new SqlStorage(prop.getProperty("db.url"), prop.getProperty("db.user"), prop.getProperty("db.password"));
} catch (IOException e) {
throw new IllegalStateException("Invalid config file " + PROPS);
}
}
public File getStorageDir() {
return storageDir;
}
public IStorage getStorage() {
return storage;
}
// private static File getHomeDir(){
// String prop = System.getProperty("homeDir");
// File homeDir = new File(prop == null? "." : prop);
// if (!homeDir.isDirectory()){
// throw new IllegalStateException(homeDir + " is not directory.");
// }
// return homeDir;
// }
}