From: Niki Roo Date: Sat, 25 May 2019 20:52:54 +0000 (+0200) Subject: extra info on bad images in ImagesUtils X-Git-Tag: fanfix-3.0.1~29^2~35 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=c48600a5014b89ffec8a46cd20da3466e0c82c56;p=fanfix.git extra info on bad images in ImagesUtils --- diff --git a/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class b/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class index b12967c..c1755b0 100644 Binary files a/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class and b/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class differ diff --git a/src/be/nikiroo/utils/android/ImageUtilsAndroid.java b/src/be/nikiroo/utils/android/ImageUtilsAndroid.java index ec1c220..b717989 100644 --- a/src/be/nikiroo/utils/android/ImageUtilsAndroid.java +++ b/src/be/nikiroo/utils/android/ImageUtilsAndroid.java @@ -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; diff --git a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java index 981ec24..90d780a 100644 --- a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java +++ b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java @@ -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;