1 package org.opentrafficsim.base;
2
3 import java.io.InputStream;
4 import java.net.URI;
5 import java.net.URISyntaxException;
6
7
8
9
10
11
12
13
14
15
16
17 public final class Resource
18 {
19
20
21 private Resource()
22 {
23
24 }
25
26
27
28
29
30
31 public static InputStream getResourceAsStream(final String name)
32 {
33 InputStream stream = Resource.class.getResourceAsStream(name);
34 if (stream != null)
35 {
36 return stream;
37 }
38 stream = Resource.class.getResourceAsStream("/resources" + name);
39 if (stream != null)
40 {
41 return stream;
42 }
43 throw new RuntimeException("Unable to load resource " + name);
44 }
45
46
47
48
49
50
51
52 public static URI getResourceAsUri(final String name) throws URISyntaxException
53 {
54 InputStream stream = Resource.class.getResourceAsStream(name);
55 if (stream != null)
56 {
57 return Resource.class.getResource(name).toURI();
58 }
59 stream = Resource.class.getResourceAsStream("/resources" + name);
60 if (stream != null)
61 {
62 return Resource.class.getResource("/resources" + name).toURI();
63 }
64 throw new RuntimeException("Unable to load resource " + name);
65
66 }
67
68 }