-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
54 lines (44 loc) · 1.61 KB
/
Config.java
File metadata and controls
54 lines (44 loc) · 1.61 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
package ru.javaops.webapp;
import ru.javaops.webapp.storage.SqlStorage;
import ru.javaops.webapp.storage.Storage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Properties;
public class Config {
private static final String PROPS = "/resumes.properties";
private static final Config INSTANCE = new Config();
private final File storageDir;
private final Storage storage;
private Config() {
try (InputStream is = Config.class.getResourceAsStream(PROPS)) {
Properties props = new Properties();
props.load(is);
storageDir = new File(props.getProperty("storage.dir"));
Class.forName(props.getProperty("db.driverClassName"));
storage = new SqlStorage(props.getProperty("db.url"), props.getProperty("db.user"), props.getProperty("db.password"));
} catch (IOException e) {
throw new IllegalStateException("Invalid config file " + PROPS);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public static Config get() {
return INSTANCE;
}
public File getStorageDir() {
return storageDir;
}
public Storage 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;
// }
}