Skip to content

Commit 04a17e8

Browse files
simplify loading wasm
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 5f31b89 commit 04a17e8

File tree

1 file changed

+6
-24
lines changed
  • providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm

1 file changed

+6
-24
lines changed

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,13 @@ public EvaluationWasm() throws WasmFileNotFound {
6868
*/
6969
private InputStream getWasmFile() throws WasmFileNotFound {
7070
try {
71-
ClassLoader classLoader = EvaluationWasm.class.getClassLoader();
72-
URL directoryUrl = classLoader.getResource("wasm");
73-
if (directoryUrl == null) {
74-
throw new RuntimeException("Directory not found");
71+
final String wasmResourcePath = "wasm/gofeatureflag-evaluation.wasi";
72+
InputStream inputStream = EvaluationWasm.class.getClassLoader().getResourceAsStream(wasmResourcePath);
73+
if (inputStream == null) {
74+
throw new WasmFileNotFound("WASM resource not found in classpath: " + wasmResourcePath);
7575
}
76-
77-
val wasmResources = classLoader.getResources("wasm");
78-
while (wasmResources.hasMoreElements()) {
79-
URL resourceUrl = wasmResources.nextElement();
80-
if ("jar".equals(resourceUrl.getProtocol()) && resourceUrl.getPath().contains("!")) {
81-
val jarPath = resourceUrl.getPath();
82-
val path = jarPath.substring(jarPath.indexOf("!") + 1);
83-
val resourceName = path + "/gofeatureflag-evaluation.wasi";
84-
val inputStream = classLoader.getResourceAsStream(resourceName);
85-
if (inputStream != null) {
86-
return inputStream;
87-
}
88-
}
89-
val inputStream = classLoader.getResourceAsStream("wasm/gofeatureflag-evaluation.wasi");
90-
if (inputStream != null) {
91-
return inputStream;
92-
}
93-
}
94-
throw new WasmFileNotFound("impossible to find the wasm file");
95-
} catch(WasmFileNotFound e) {
76+
return inputStream;
77+
} catch (WasmFileNotFound e) {
9678
throw e;
9779
} catch (Exception e) {
9880
throw new WasmFileNotFound(e);

0 commit comments

Comments
 (0)