commit | author | age
|
2f2aa7
|
1 |
/* |
U |
2 |
Helix - Dateiverwaltung |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.calypso.neu; |
|
19 |
|
|
20 |
import java.io.File; |
|
21 |
import java.io.FileInputStream; |
|
22 |
import java.io.FileNotFoundException; |
|
23 |
import java.io.IOException; |
|
24 |
import java.io.InputStream; |
|
25 |
import java.util.Properties; |
|
26 |
import java.util.logging.Level; |
|
27 |
import java.util.logging.Logger; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @author Ulrich Hilger |
|
32 |
* @version 1, 01.06.2021 |
|
33 |
*/ |
|
34 |
public class AppProperties extends Properties { |
|
35 |
|
|
36 |
public static final String EMPTY_STR = ""; |
|
37 |
public static final int INT_ZERO = 0; |
|
38 |
|
|
39 |
public String getString(String key) { |
|
40 |
Object o = this.get(key); |
|
41 |
if(o instanceof String) { |
|
42 |
return (String) o; |
|
43 |
} else { |
|
44 |
return EMPTY_STR; |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public int getInt(String key) { |
|
49 |
Object o = this.get(key); |
|
50 |
if(o instanceof String) { |
|
51 |
String intStr = (String) o; |
|
52 |
return Integer.parseInt(intStr); |
|
53 |
} else { |
|
54 |
return INT_ZERO; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
public void readFile(String fName) { |
|
59 |
Logger.getLogger(AppProperties.class.getName()).log(Level.INFO, fName); |
|
60 |
InputStream in = null; |
|
61 |
try { |
|
62 |
// Einstellungen aus Datei lesen |
|
63 |
//AppProperties einst = new AppProperties(); |
|
64 |
File einstellungenDatei = new File(fName); |
|
65 |
in = new FileInputStream(einstellungenDatei); |
|
66 |
|
|
67 |
//BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
|
68 |
//String line = br.readLine(); |
|
69 |
//while(line != null) { |
|
70 |
// System.out.println(line); |
|
71 |
// line = br.readLine(); |
|
72 |
//} |
|
73 |
//br.close(); |
|
74 |
|
|
75 |
|
|
76 |
load(in); |
|
77 |
in.close(); |
|
78 |
} catch (FileNotFoundException ex) { |
|
79 |
Logger.getLogger(AppProperties.class.getName()).log(Level.SEVERE, null, ex); |
|
80 |
} catch (IOException ex) { |
|
81 |
Logger.getLogger(AppProperties.class.getName()).log(Level.SEVERE, null, ex); |
|
82 |
} finally { |
|
83 |
try { |
|
84 |
in.close(); |
|
85 |
} catch (IOException ex) { |
|
86 |
Logger.getLogger(AppProperties.class.getName()).log(Level.SEVERE, null, ex); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
} |