-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.java
More file actions
40 lines (31 loc) · 1.12 KB
/
Copy pathConfig.java
File metadata and controls
40 lines (31 loc) · 1.12 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
package ru.javawebinar.basejava;
import ru.javawebinar.basejava.storage.SqlStorage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
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 SqlStorage sqlStorage;
private Config() {
try (InputStream is = Config.class.getClassLoader().getResourceAsStream(PROPS)) {
Properties props = new Properties();
props.load(is);
storageDir = new File(props.getProperty("storage.dir"));
sqlStorage = new SqlStorage(props.getProperty("db.url"), props.getProperty("db.user"), props.getProperty("db.password"));
} catch (IOException e) {
throw new IllegalStateException("Invalid config file " + PROPS);
}
}
public static Config get() {
return INSTANCE;
}
public File getStorageDir() {
return storageDir;
}
public SqlStorage getSqlStorage() {
return sqlStorage;
}
}