Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[nikiroo-utils.git] / src / be / nikiroo / utils / ui / ImageUtilsAwt.java
index 6e9160f5c02f38964e343035d4cda7a7c7f34cff..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.
@@ -18,6 +19,13 @@ import be.nikiroo.utils.ImageUtils;
  * @author niki
  */
 public class ImageUtilsAwt extends ImageUtils {
+       @Override
+       protected boolean check() {
+               // Will not work if ImageIO is not available
+               ImageIO.getCacheDirectory();
+               return true;
+       }
+
        @Override
        public void saveAsImage(Image img, File target, String format)
                        throws IOException {
@@ -91,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;