From: Niki Roo Date: Sun, 10 Dec 2017 17:47:35 +0000 (+0100) Subject: Auto cache cleaning + better err in ImageUtilsAnd X-Git-Tag: fanfix-3.0.1~29^2~225 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=e704a41477b85b6bb76dff4181df132176aec112;p=fanfix.git Auto cache cleaning + better err in ImageUtilsAnd --- diff --git a/src/be/nikiroo/utils/Cache.java b/src/be/nikiroo/utils/Cache.java index 2b32d78..bba88bb 100644 --- a/src/be/nikiroo/utils/Cache.java +++ b/src/be/nikiroo/utils/Cache.java @@ -135,7 +135,12 @@ public class Cache { */ private boolean check(File cached, boolean allowTooOld, boolean stable) { if (cached.exists() && cached.isFile()) { - if (allowTooOld || !isOld(cached, stable)) { + if (!allowTooOld && isOld(cached, stable)) { + if (!cached.delete()) { + tracer.error("Cannot delete temporary file: " + + cached.getAbsolutePath()); + } + } else { return true; } } diff --git a/src/be/nikiroo/utils/android/ImageUtilsAndroid.java b/src/be/nikiroo/utils/android/ImageUtilsAndroid.java index 483c44f..b2359e6 100644 --- a/src/be/nikiroo/utils/android/ImageUtilsAndroid.java +++ b/src/be/nikiroo/utils/android/ImageUtilsAndroid.java @@ -2,15 +2,17 @@ package be.nikiroo.utils.android; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import be.nikiroo.utils.Image; -import be.nikiroo.utils.ImageUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.ImageUtils; + /** - * This class offer some utilities based around images and uses the Android framework. + * This class offer some utilities based around images and uses the Android + * framework. * * @author niki */ @@ -62,7 +64,22 @@ public class ImageUtilsAndroid extends ImageUtils { Bitmap image = BitmapFactory.decodeByteArray(img.getData(), 0, img.getData().length); if (image == null) { - throw new IOException("Failed to convert input to image"); + int size = img.getData().length; + String ssize = size + " byte"; + if (size > 1) { + ssize = size + " bytes"; + if (size >= 1000) { + size = size / 1000; + ssize = size + " kb"; + if (size > 1000) { + size = size / 1000; + ssize = size + " MB"; + } + } + } + + throw new IOException( + "Failed to convert input to image, size was: " + ssize); } return image; diff --git a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java index 26d14aa..0c69dc4 100644 --- a/src/be/nikiroo/utils/ui/ImageUtilsAwt.java +++ b/src/be/nikiroo/utils/ui/ImageUtilsAwt.java @@ -61,7 +61,7 @@ public class ImageUtilsAwt extends ImageUtils { * @throws IOException * in case of IO error */ - static public BufferedImage fromImage(Image img) throws IOException { + public static BufferedImage fromImage(Image img) throws IOException { InputStream in = new ByteArrayInputStream(img.getData()); int orientation;