1 |
package skrueger.lang; |
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileNotFoundException; |
5 |
import java.io.IOException; |
6 |
import java.io.InputStream; |
7 |
import java.net.URL; |
8 |
import java.util.Properties; |
9 |
|
10 |
import org.apache.log4j.Logger; |
11 |
|
12 |
import schmitzm.io.FileOutputStream; |
13 |
|
14 |
/** |
15 |
* Erlaubt es eine {@link Properties} Instanz mit einer Zeile zu initialisieren |
16 |
* und mit den Werten einer Datei zu befüllen. Alle Exceptions werden zu |
17 |
* {@link RuntimeException}s. |
18 |
* |
19 |
* @author Stefan A. Tzeggai |
20 |
* |
21 |
*/ |
22 |
public class PropertiesLoaded extends Properties { |
23 |
private static Logger log = Logger.getLogger(PropertiesLoaded.class); |
24 |
|
25 |
/** |
26 |
* Erlaubt es eine {@link Properties} Instanz mit einer Zeile zu |
27 |
* initialisieren und mit den Werten einer Datei zu befüllen. Alle |
28 |
* Exceptions werden zu {@link RuntimeException}s. |
29 |
* |
30 |
* @author Stefan A. Tzeggai |
31 |
* |
32 |
*/ |
33 |
public PropertiesLoaded(URL loadFrom) { |
34 |
super(); |
35 |
|
36 |
load(loadFrom); |
37 |
} |
38 |
|
39 |
/** |
40 |
* Erlaubt es eine {@link Properties} Instanz mit einer Zeile zu |
41 |
* initialisieren und mit den Werten einer Datei zu befüllen. Alle |
42 |
* Exceptions werden zu {@link RuntimeException}s. |
43 |
* |
44 |
* @author Stefan A. Tzeggai |
45 |
* |
46 |
*/ |
47 |
public PropertiesLoaded(URL loadFrom, Properties defaults) { |
48 |
super(defaults); |
49 |
load(loadFrom); |
50 |
} |
51 |
|
52 |
/** |
53 |
* Erlaubt es eine {@link Properties} Instanz mit einer Zeile zu |
54 |
* initialisieren und mit den Werten einer Datei zu befüllen. Alle |
55 |
* Exceptions werden zu {@link RuntimeException}s. |
56 |
* |
57 |
* @author Stefan A. Tzeggai |
58 |
*/ |
59 |
public PropertiesLoaded() { |
60 |
super(); |
61 |
} |
62 |
|
63 |
/** |
64 |
* Erlaubt es eine {@link Properties} Instanz mit einer Zeile zu |
65 |
* initialisieren und mit den Werten einer Datei zu befüllen. Alle |
66 |
* Exceptions werden zu {@link RuntimeException}s. |
67 |
* |
68 |
* @author Stefan A. Tzeggai |
69 |
* |
70 |
*/ |
71 |
public PropertiesLoaded(Properties defaults) { |
72 |
super(defaults); |
73 |
} |
74 |
|
75 |
/** |
76 |
* Erlaubt es eine {@link Properties} Instanz mit einer Zeile zu |
77 |
* initialisieren und mit den Werten einer Datei zu befüllen. Alle |
78 |
* Exceptions werden zu {@link RuntimeException}s. |
79 |
* |
80 |
* @author Stefan A. Tzeggai |
81 |
* |
82 |
*/ |
83 |
public void load(URL loadFrom) { |
84 |
try { |
85 |
|
86 |
InputStream openStream = null; |
87 |
try { |
88 |
openStream = loadFrom.openStream(); |
89 |
load(openStream); |
90 |
} finally { |
91 |
if (openStream != null) |
92 |
openStream.close(); |
93 |
} |
94 |
|
95 |
} catch (Exception e) { |
96 |
throw new RuntimeException(e); |
97 |
} |
98 |
} |
99 |
|
100 |
public void save(File f) throws FileNotFoundException, IOException { |
101 |
store(new FileOutputStream(f), ""); |
102 |
} |
103 |
|
104 |
} |