2
2
3
3
import cc .sukazyo .restools .impl .disk .DiskPackage ;
4
4
import cc .sukazyo .restools .impl .jar .JarPackage ;
5
+ import cc .sukazyo .restools .utils .PathsHelper ;
5
6
6
7
import javax .annotation .Nonnull ;
7
8
import javax .annotation .Nullable ;
@@ -32,10 +33,13 @@ class UnsupportedPackageTypeException extends Exception {}
32
33
* @return A {@link ResourcePackage} that contains the resource.
33
34
* @throws UnsupportedPackageTypeException If the resource location cannot be read by any
34
35
* of the known implementations.
36
+ * @throws NoSuchResourceException If the identifierFilePath is not exists (either directory
37
+ * or file) in classloader's all the classpath.
35
38
*
36
39
* @since 0.3.0
37
40
*/
38
- static ResourcePackage get (@ Nonnull ClassLoader classLoader , @ Nonnull String ... identifierFilePath ) throws UnsupportedPackageTypeException {
41
+ static ResourcePackage get (@ Nonnull ClassLoader classLoader , @ Nonnull String ... identifierFilePath )
42
+ throws UnsupportedPackageTypeException , NoSuchResourceException {
39
43
40
44
try { return new DiskPackage (classLoader , identifierFilePath ); } catch (UnsupportedPackageTypeException ignored ) {}
41
45
try { return new JarPackage (classLoader , identifierFilePath ); } catch (UnsupportedPackageTypeException ignored ) {}
@@ -44,6 +48,28 @@ static ResourcePackage get (@Nonnull ClassLoader classLoader, @Nonnull String...
44
48
45
49
}
46
50
51
+ /**
52
+ * Get a resource package.
53
+ * <p>
54
+ * Different with the v0.2.x and older, the ResourcePackage always locates in the root of the
55
+ * classpath, instead of the old behavior of the v0.2.x, which locates in the given path.
56
+ *
57
+ * @param classLoader the {@link ClassLoader} that is used to load the resource.
58
+ * @param identifierFilePath Path of a resource, used to locate a resource package. The path
59
+ * will be parsed to an array using {@link PathsHelper#parseString(String)}.
60
+ * @return A {@link ResourcePackage} that contains the resource.
61
+ * @throws UnsupportedPackageTypeException If the resource location cannot be read by any
62
+ * of the known implementations.
63
+ * @throws NoSuchResourceException If the identifierFilePath is not exists (either directory
64
+ * or file) in classloader's all the classpath.
65
+ *
66
+ * @since 0.3.0
67
+ */
68
+ static ResourcePackage get (@ Nonnull ClassLoader classLoader , @ Nonnull String identifierFilePath )
69
+ throws UnsupportedPackageTypeException , NoSuchResourceException {
70
+ return get (classLoader , PathsHelper .parseString (identifierFilePath ));
71
+ }
72
+
47
73
/**
48
74
* Get the resource package using the current thread's {@link ClassLoader}.
49
75
* <p>
@@ -54,10 +80,26 @@ static ResourcePackage get (@Nonnull ClassLoader classLoader, @Nonnull String...
54
80
*
55
81
* @since 0.3.0
56
82
*/
57
- static ResourcePackage get (@ Nonnull String ... identifierFilePath ) throws UnsupportedPackageTypeException {
83
+ static ResourcePackage get (@ Nonnull String ... identifierFilePath )
84
+ throws UnsupportedPackageTypeException , NoSuchResourceException {
58
85
return get (Thread .currentThread ().getContextClassLoader (), identifierFilePath );
59
86
}
60
87
88
+ /**
89
+ * Get the resource package using the current thread's {@link ClassLoader}.
90
+ * <p>
91
+ * This is an alias of {@link #get(ClassLoader, String)}, in most cases where there's no
92
+ * custom classloader, this method is enough to work.
93
+ *
94
+ * @see #get(ClassLoader, String)
95
+ *
96
+ * @since 0.3.0
97
+ */
98
+ static ResourcePackage get (@ Nonnull String identifierFilePath )
99
+ throws UnsupportedPackageTypeException , NoSuchResourceException {
100
+ return get (PathsHelper .parseString (identifierFilePath ));
101
+ }
102
+
61
103
/**
62
104
* Get the associated {@link ResourcePackage} that contains this {@link ResourceDirectory}.
63
105
* <p>
0 commit comments