From e7356d0bdbce5dd0bfb64b08f1f61ff41778e010 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Mon, 30 Dec 2013 15:37:11 +0100
Subject: IOUtil: Add convenience compound class 'ClassResources'

---
 src/java/com/jogamp/common/util/IOUtil.java | 37 +++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

(limited to 'src/java/com/jogamp/common')

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
@@ -634,6 +634,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>
-- 
cgit v1.2.3