X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FImageUtilsAwt.java;h=4cf12c04cd0573629d90ed6e376be7c5ca6e7155;hb=d46b7b96f94e88a776bcd2dfd756549ffb300cc9;hp=367e757a81ede843a9273f68cafbe6f816374297;hpb=10b6023d2b40921bfc55abf414a988ca19e5e142;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java index 367e757..4cf12c0 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. @@ -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;