Skip to content

Commit 51a8083

Browse files
committed
extra ConfigLoader methods
1 parent a70bec9 commit 51a8083

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/net/openhft/chronicle/wire/utils/ConfigLoader.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.openhft.chronicle.core.io.IOTools;
44
import net.openhft.chronicle.wire.TextWire;
5+
import net.openhft.chronicle.wire.WireType;
56

67
import java.io.IOException;
78
import java.nio.charset.StandardCharsets;
@@ -51,13 +52,32 @@ public static <T> T loadFromFile(Class<?> classLoader, String filename, Properti
5152
return loadWithProperties(loadFile(classLoader, filename), properties);
5253
}
5354

55+
public static <T> T loadFromFile(Class<T> expectedClass, Class<?> classLoader, String filename, Properties properties) throws IOException {
56+
return loadWithProperties(expectedClass, loadFile(classLoader, filename), properties);
57+
}
58+
5459
@SuppressWarnings("unchecked")
5560
public static <T> T load(String fileAsString) {
5661
return (T) TextWire.from(replaceTokensWithProperties(fileAsString)).readObject();
5762
}
5863

64+
@SuppressWarnings("unchecked")
65+
public static <T> T loadWithProperties(String fileAsString) {
66+
return loadWithProperties(fileAsString, System.getProperties());
67+
}
68+
5969
@SuppressWarnings("unchecked")
6070
public static <T> T loadWithProperties(String fileAsString, Properties properties) {
61-
return (T) TextWire.from(replaceTokensWithProperties(fileAsString, properties)).readObject();
71+
return loadWithProperties(null, fileAsString, properties);
72+
}
73+
74+
@SuppressWarnings("unchecked")
75+
public static <T> T loadWithProperties(Class<T> expectedClass, String fileAsString) {
76+
return loadWithProperties(expectedClass, fileAsString, System.getProperties());
77+
}
78+
79+
@SuppressWarnings("unchecked")
80+
public static <T> T loadWithProperties(Class<T> expectedClass, String fileAsString, Properties properties) {
81+
return WireType.TEXT.fromString(expectedClass, replaceTokensWithProperties(fileAsString, properties));
6282
}
6383
}

0 commit comments

Comments
 (0)