extra info on bad images in ImagesUtils
authorNiki Roo <niki@nikiroo.be>
Sat, 25 May 2019 20:52:54 +0000 (22:52 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 25 May 2019 20:52:54 +0000 (22:52 +0200)
libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class
src/be/nikiroo/utils/android/ImageUtilsAndroid.java
src/be/nikiroo/utils/ui/ImageUtilsAwt.java

index b12967c2003db963d05f9f2002f57020a142d565..c1755b0d1bbf0e8ed12f7b2e239a633b4d164a14 100644 (file)
Binary files a/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class and b/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class differ
index ec1c2205af4e7beb2db5f571b39034735ce84ba7..b717989505a9b173065b7d7be7cd238f89de2b31 100644 (file)
@@ -76,9 +76,19 @@ public class ImageUtilsAndroid extends ImageUtils {
                try {
                        Bitmap image = BitmapFactory.decodeStream(stream);
                        if (image == null) {
+                               String extra = "";
+                               if (img.getSize() <= 1024) {
+                                       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);
+                                               "Failed to convert input to image, size was: " + ssize
+                                                               + extra);
                        }
 
                        return image;
index 981ec247f87b0579d852a143632074bddf9b036c..90d780ae501afbfc436fd4fde803e7cf18674435 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.
@@ -98,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() <= 1024) {
+                                       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;