forked from cdimascio/dotenv-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasspathHelper.java
More file actions
36 lines (31 loc) · 1.07 KB
/
ClasspathHelper.java
File metadata and controls
36 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.github.cdimascio.dotenv.internal;
import io.github.cdimascio.dotenv.DotenvException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.stream.Stream;
/**
* Classpath helper
*/
public class ClasspathHelper {
static Stream<String> loadFileFromClasspath(String location) {
final var loader = ClasspathHelper.class;
var inputStream = loader.getResourceAsStream(location);
if (inputStream == null) {
inputStream = loader.getResourceAsStream(location);
}
if (inputStream == null) {
inputStream = ClassLoader.getSystemResourceAsStream(location);
}
if (inputStream == null) {
throw new DotenvException("Could not find "+location+" on the classpath");
}
final var scanner = new Scanner(inputStream, "utf-8");
final var lines = new ArrayList<String>();
while (scanner.hasNext()) {
lines.add(scanner.nextLine());
}
scanner.close();
return lines.stream();
}
}