From c48600a5014b89ffec8a46cd20da3466e0c82c56 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 25 May 2019 22:52:54 +0200 Subject: [PATCH] extra info on bad images in ImagesUtils --- .../utils/android/ImageUtilsAndroid.class | Bin 3083 -> 3353 bytes .../utils/android/ImageUtilsAndroid.java | 12 +++++++++++- src/be/nikiroo/utils/ui/ImageUtilsAwt.java | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class b/libs/bin/be/nikiroo/utils/android/ImageUtilsAndroid.class index b12967c2003db963d05f9f2002f57020a142d565..c1755b0d1bbf0e8ed12f7b2e239a633b4d164a14 100644 GIT binary patch delta 1260 zcmYk6?N?M)6vlt&a))!dU3?i*7$KQ5lb4yOG$SfSLd=9g0X1SG2blO-{8gtbN1PLKYKst*=O#FinD79zy0&m z&%j2$cc~#+BGwa{ewQMiblJcGmugZj0~~Z2B&~VMVaPb2E)nOj=8)#F%QBJFML@^{Wvzp(1iTu6aXnLR#~t&xybx zYN_*ho6U-fL#c^W!*I5tZFnTzna_>obKSY|bZXS2mUle5>G61%lbTZ=@8L^nkJG&G zpDJ4GoZ$nH4>{}47Nx`InDO|ClLmO+<74XlxLsK|#|7j0MEH4p%4eF-J-*;e1s-2< zQE^i&dN7;Gr8BvvsA5GxXe5;xY7ipBnIVr$e60xW?P-fQno{2=R^5O^^BK9o@JMQ4 zL`L$h$7Q}##M;D_9*pL){-nKLE`7m1qssl?t@5h}LVsAR^iVq2n#!dVc1>+xi=w=y zuf z$zJ>;R=a&!EDM8n18=3|Rs|JSFJ|4SU~vzd1*^D^Mu|x+bw#pE1Uuummi(e(e#q@E znC?mO*2&AdpC&Xb=;Z+(Bt#kect{u&bA($Yx>bCFUg}}2X0}NOW3}*bz+i?}wo5IS zY1-H!9UqZ+9K9e?Xw6Q|qncfsc1?$-kPwQRPP_6is&{C1%bVL%LYH7{saz_|eaQqf+2jYvoAR|djs65^=5nX1$0sh?+A?;Oj+YiC(GPj#<^qTyTTxJ}Np zgcBEWn(Xkp0CJ7O?M?PPrM>^5)=O5zmLh+qF85%>5lZ%df^_dKxhP=vastT!a!f-O= zbG}f0$d{ao=DddFY0iY4<*Vp#Z**XiuS34!L`a5jL%yTYp>|WgR2nO1j*b`0qnYBN zd|@tK~BXE z&xnD`(&*2so6fT6TrgO%Eq7txiN{LXG0fLHcvdec!2*U^%^D#c5#UPJDhAUJaINx62(4%WvsrrE&r!U~w;1yS~SNx$bXcQuDGbQ(4qx(u5Pn+=sMqGfp5PyfS`ZbSEO z!`3QZQH@ouTFkV2%UO|IidhC-*;y9$v|J(8+xizxx-Ggwy6+m*BiEQWGRNaJi)VQv zr|&E^b1b;t+Sf8meeUvl-`bRaU5E+I*ijK&hbVW*dhsrr)DpE!(5oT(^wj&QWt*fK zQo*oB9#ZyjtaMg{YDv@cVC1$~IJ={+SQ;%_BJ>KyiDgLR{zto^->~Jbq;}0(t46<- fVCy48yXt4RyPa0q8hKg$Sz9_&TFp*A>rCAP4FQ*6 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; -- 2.27.0