Add 'src/be/nikiroo/utils/' from commit '46add0670fdee4bd936a13fe2448c5e20a7ffd0a'
[nikiroo-utils.git] / src / be / nikiroo / utils / ui / ImageUtilsAwt.java
index 367e757a81ede843a9273f68cafbe6f816374297..4cf12c04cd0573629d90ed6e376be7c5ca6e7155 100644 (file)
@@ -11,6 +11,7 @@ import javax.imageio.ImageIO;
 
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.StringUtils;
 
 /**
  * This class offer some utilities based around images and uses java.awt.
@@ -20,9 +21,8 @@ import be.nikiroo.utils.ImageUtils;
 public class ImageUtilsAwt extends ImageUtils {
        @Override
        protected boolean check() {
-               // If we can get the class, it means we have access to it
-               @SuppressWarnings("unused")
-               Object test = ImageIO.class;
+               // Will not work if ImageIO is not available
+               ImageIO.getCacheDirectory();
                return true;
        }
 
@@ -99,7 +99,19 @@ public class ImageUtilsAwt extends ImageUtils {
                        }
 
                        if (image == null) {
-                               throw new IOException("Failed to convert input to image");
+                               String extra = "";
+                               if (img.getSize() <= 2048) {
+                                       try {
+                                               extra = ", content: "
+                                                               + new String(img.getData(), "UTF-8");
+                                       } catch (Exception e) {
+                                               extra = ", content unavailable";
+                                       }
+                               }
+                               String ssize = StringUtils.formatNumber(img.getSize());
+                               throw new IOException(
+                                               "Failed to convert input to image, size was: " + ssize
+                                                               + extra);
                        }
 
                        // Note: this code has been found on Internet;