aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/IOUtil.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-12-30 15:37:11 +0100
committerSven Gothel <[email protected]>2013-12-30 15:37:11 +0100
commite7356d0bdbce5dd0bfb64b08f1f61ff41778e010 (patch)
tree4994189a4164ce393ca9bf8e7786a26377cbaa4a /src/java/com/jogamp/common/util/IOUtil.java
parent5b1cacb04b19be85cb11cbe55c50c960b494ec05 (diff)
IOUtil: Add convenience compound class 'ClassResources'
Diffstat (limited to 'src/java/com/jogamp/common/util/IOUtil.java')
-rw-r--r--src/java/com/jogamp/common/util/IOUtil.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java
index bbda235..2bcb58c 100644
--- a/src/java/com/jogamp/common/util/IOUtil.java
+++ b/src/java/com/jogamp/common/util/IOUtil.java
@@ -635,6 +635,43 @@ public class IOUtil {
*/
/**
+ * Helper compound associating a class instance and resource paths
+ * to be {@link #resolve(int) resolved} at a later time.
+ */
+ public static class ClassResources {
+ /** Class instance used to {@link #resolve(int)} the {@link #resourcePaths}. */
+ public final Class<?> contextCL;
+
+ /** Resource paths, see {@link #resolve(int)}. */
+ public final String[] resourcePaths;
+
+ /** Returns the number of resources, i.e. <code>resourcePaths.length</code>. */
+ public final int resourceCount() { return resourcePaths.length; }
+
+ /**
+ * @param contextCL class instance to {@link #resolve(int)} {@link #resourcePaths}.
+ * @param resourcePaths array of strings denominating multiple resource paths. None shall be null.
+ */
+ public ClassResources(Class<?> contextCL, String[] resourcePaths) {
+ for(int i=resourcePaths.length-1; i>=0; i--) {
+ if( null == resourcePaths[i] ) {
+ throw new IllegalArgumentException("resourcePath["+i+"] is null");
+ }
+ }
+ this.contextCL = contextCL;
+ this.resourcePaths = resourcePaths;
+ }
+
+ /**
+ * Resolving one of the {@link #resourcePaths} indexed by <code>uriIndex</code> using {@link #contextCL} and {@link IOUtil#getResource(Class, String)}.
+ * @throws ArrayIndexOutOfBoundsException if <code>uriIndex</code> is < 0 or >= {@link #resourceCount()}.
+ */
+ public URLConnection resolve(int uriIndex) throws ArrayIndexOutOfBoundsException {
+ return getResource(contextCL, resourcePaths[uriIndex]);
+ }
+ }
+
+ /**
* Locating a resource using {@link #getResource(String, ClassLoader)}:
* <ul>
* <li><i>relative</i>: <code>context</code>'s package name-path plus <code>resourcePath</code> via <code>context</code>'s ClassLoader.