Skip to content

Commit d394c5e

Browse files
authored
Load mail.properties from resources (#118)
* Load mail.properties as resource * Add JDs
1 parent a3a7582 commit d394c5e

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

subscription-provider/src/main/java/life/qbic/logging/subscription/provider/mail/property/MailPropertyLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.File;
66
import java.io.IOException;
7+
import java.io.InputStream;
78
import java.util.Properties;
89

910
/**
@@ -22,9 +23,9 @@ public static MailPropertyLoader create() {
2223
}
2324

2425
public Properties load() throws IOException {
25-
String file = requireNonNull(getClass().getClassLoader().getResource(PROPERTIES),
26-
"Cannot find property file. Please make sure to provide a file 'mail.properties' in the resources").getFile();
27-
return PropertyFileParser.parse(new File(file));
26+
InputStream stream = requireNonNull(getClass().getClassLoader().getResourceAsStream(PROPERTIES),
27+
"Cannot find property file. Please make sure to provide a file 'mail.properties' in the resources");
28+
return PropertyFileParser.parse(stream);
2829
}
2930

3031
}

subscription-provider/src/main/java/life/qbic/logging/subscription/provider/mail/property/PropertyFileParser.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.io.FileInputStream;
88
import java.io.IOException;
9+
import java.io.InputStream;
910
import java.util.Properties;
1011

1112
/**
@@ -52,6 +53,25 @@ public static Properties parse(File file) throws IOException {
5253
return properties;
5354
}
5455

56+
/**
57+
* Parses an input stream for defined properties and resolves present placeholder against visible
58+
* environment variables.
59+
* @param inputStream the input stream with the defined properties
60+
* @return a {@link Properties} object with the parsed properties
61+
* @throws IOException if the file cannot be accessed
62+
* @since 1.0.0
63+
*/
64+
public static Properties parse(InputStream inputStream) throws IOException {
65+
requireNonNull(inputStream, "Input stream must not be null");
66+
67+
var properties = new Properties();
68+
properties.load(inputStream);
69+
70+
properties = resolvePlaceholders(properties);
71+
72+
return properties;
73+
}
74+
5575
private static Properties resolvePlaceholders(Properties properties) {
5676
var resolvedProperties = new Properties();
5777
properties.forEach((property, value) -> {

0 commit comments

Comments
 (0)