update from master
[fanfix.git] / supported / BasicSupportImages.java
index 69a7c86720002b18c36bd2a4a79ee72353984429..f56b50c2b67a6dd9f5a4b1e0de572767d0a42dde 100644 (file)
@@ -20,16 +20,32 @@ public class BasicSupportImages {
         * Check if the given resource can be a local image or a remote image, then
         * refresh the cache with it if it is.
         * 
+        * @param support
+        *            the support to use to download the resource (can be NULL)
         * @param dir
         *            the local directory to search, if any
         * @param line
         *            the resource to check
         * 
         * @return the image if found, or NULL
-        * 
         */
        public Image getImage(BasicSupport support, File dir, String line) {
                URL url = getImageUrl(support, dir, line);
+               return getImage(support,url);
+       }
+       
+       /**
+        * Check if the given resource can be a local image or a remote image, then
+        * refresh the cache with it if it is.
+        * 
+        * @param support
+        *            the support to use to download the resource (can be NULL)
+        * @param url
+        *            the actual URL to check (file or remote, can be NULL)
+        * 
+        * @return the image if found, or NULL
+        */
+       public Image getImage(BasicSupport support, URL url) {
                if (url != null) {
                        if ("file".equals(url.getProtocol())) {
                                if (new File(url.getPath()).isDirectory()) {
@@ -38,8 +54,14 @@ public class BasicSupportImages {
                        }
                        InputStream in = null;
                        try {
-                               in = Instance.getCache().open(url, support, true);
-                               return new Image(in);
+                               in = Instance.getInstance().getCache().open(url, support, true);
+                               Image img = new Image(in);
+                               if (img.getSize() == 0) {
+                                       img.close();
+                                       throw new IOException(
+                                                       "Empty image not accepted");
+                               }
+                               return img;
                        } catch (IOException e) {
                        } finally {
                                if (in != null) {
@@ -58,6 +80,8 @@ public class BasicSupportImages {
         * Check if the given resource can be a local image or a remote image, then
         * refresh the cache with it if it is.
         * 
+        * @param support
+        *            the support to use to download the resource (can be NULL)
         * @param dir
         *            the local directory to search, if any
         * @param line
@@ -108,7 +132,7 @@ public class BasicSupportImages {
                                // try for URLs
                                try {
                                        for (String ext : getImageExt(true)) {
-                                               if (Instance.getCache()
+                                               if (Instance.getInstance().getCache()
                                                                .check(new URL(line + ext), true)) {
                                                        url = new URL(line + ext);
                                                        break;
@@ -120,7 +144,7 @@ public class BasicSupportImages {
                                                for (String ext : getImageExt(true)) {
                                                        try {
                                                                url = new URL(line + ext);
-                                                               Instance.getCache().refresh(url, support, true);
+                                                               Instance.getInstance().getCache().refresh(url, support, true);
                                                                break;
                                                        } catch (IOException e) {
                                                                // no image with this ext
@@ -136,7 +160,7 @@ public class BasicSupportImages {
                        // refresh the cached file
                        if (url != null) {
                                try {
-                                       Instance.getCache().refresh(url, support, true);
+                                       Instance.getInstance().getCache().refresh(url, support, true);
                                } catch (IOException e) {
                                        // woops, broken image
                                        url = null;