commit | author | age
|
2f2aa7
|
1 |
/* |
933ccd
|
2 |
Calypso - Media Player Remote Control via HTTP for Raspberry Pi |
U |
3 |
Copyright (C) 2021-2023 Ulrich Hilger |
2f2aa7
|
4 |
|
933ccd
|
5 |
This program is free software: you can redistribute it and/or modify |
U |
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. |
2f2aa7
|
9 |
|
933ccd
|
10 |
This program is distributed in the hope that it will be useful, |
U |
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. |
2f2aa7
|
14 |
|
933ccd
|
15 |
You should have received a copy of the GNU Affero General Public License |
U |
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
e27ab1
|
19 |
package de.uhilger.calypso; |
2f2aa7
|
20 |
|
U |
21 |
import java.io.File; |
|
22 |
import java.io.FileInputStream; |
|
23 |
import java.io.FileNotFoundException; |
|
24 |
import java.io.IOException; |
|
25 |
import java.io.InputStream; |
|
26 |
import java.util.Properties; |
|
27 |
import java.util.logging.Level; |
|
28 |
import java.util.logging.Logger; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author Ulrich Hilger |
|
33 |
* @version 1, 01.06.2021 |
|
34 |
*/ |
|
35 |
public class AppProperties extends Properties { |
|
36 |
|
|
37 |
public static final String EMPTY_STR = ""; |
|
38 |
public static final int INT_ZERO = 0; |
|
39 |
|
|
40 |
public String getString(String key) { |
|
41 |
Object o = this.get(key); |
|
42 |
if(o instanceof String) { |
|
43 |
return (String) o; |
|
44 |
} else { |
|
45 |
return EMPTY_STR; |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
public int getInt(String key) { |
|
50 |
Object o = this.get(key); |
|
51 |
if(o instanceof String) { |
|
52 |
String intStr = (String) o; |
|
53 |
return Integer.parseInt(intStr); |
|
54 |
} else { |
|
55 |
return INT_ZERO; |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
public void readFile(String fName) { |
|
60 |
Logger.getLogger(AppProperties.class.getName()).log(Level.INFO, fName); |
|
61 |
InputStream in = null; |
|
62 |
try { |
|
63 |
File einstellungenDatei = new File(fName); |
|
64 |
in = new FileInputStream(einstellungenDatei); |
|
65 |
load(in); |
|
66 |
in.close(); |
|
67 |
} catch (FileNotFoundException ex) { |
|
68 |
Logger.getLogger(AppProperties.class.getName()).log(Level.SEVERE, null, ex); |
|
69 |
} catch (IOException ex) { |
|
70 |
Logger.getLogger(AppProperties.class.getName()).log(Level.SEVERE, null, ex); |
|
71 |
} finally { |
|
72 |
try { |
|
73 |
in.close(); |
|
74 |
} catch (IOException ex) { |
|
75 |
Logger.getLogger(AppProperties.class.getName()).log(Level.SEVERE, null, ex); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
} |