X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FCache.java;h=dcbde74ea4b053ae512c7ed9149114af5f4aa77e;hb=530d4062471346d6ececf76d74a0358c91323998;hp=1e590547f3842070e01d8758023a8a933102b6f1;hpb=2ee6c205bfacff9e9a3103e7738afcd5e3267d3f;p=fanfix.git diff --git a/src/be/nikiroo/utils/Cache.java b/src/be/nikiroo/utils/Cache.java index 1e59054..dcbde74 100644 --- a/src/be/nikiroo/utils/Cache.java +++ b/src/be/nikiroo/utils/Cache.java @@ -19,6 +19,7 @@ public class Cache { private File dir; private long tooOldChanging; private long tooOldStable; + private TraceHandler tracer = new TraceHandler(); /** * Create a new {@link Cache} object. @@ -53,6 +54,25 @@ public class Cache { } } + /** + * The traces handler for this {@link Cache}. + * + * @return the traces handler + */ + public TraceHandler getTraceHandler() { + return tracer; + } + + /** + * The traces handler for this {@link Cache}. + * + * @param tracer + * the new traces handler + */ + public void setTraceHandler(TraceHandler tracer) { + this.tracer = tracer; + } + /** * Check the resource to see if it is in the cache. * @@ -91,24 +111,6 @@ public class Cache { return clean(onlyOld, dir); } - /** - * Trace information (info/error) generated by this class. - *

- * You can override it if you don't want the default sysout/syserr. - * - * @param message - * the message - * @param error - * TRUE for error messages, FALSE for information messages - */ - protected void trace(String message, boolean error) { - if (error) { - System.err.println(message); - } else { - System.out.println(message); - } - } - /** * Clean the cache (delete the cached items) in the given cache directory. * @@ -130,8 +132,8 @@ public class Cache { if (file.delete()) { num++; } else { - trace("Cannot delete temporary file: " - + file.getAbsolutePath(), true); + tracer.error("Cannot delete temporary file: " + + file.getAbsolutePath()); } } } @@ -304,8 +306,8 @@ public class Cache { long time = new Date().getTime() - file.lastModified(); if (time < 0) { - trace("Timestamp in the future for file: " + file.getAbsolutePath(), - true); + tracer.error("Timestamp in the future for file: " + + file.getAbsolutePath()); } return time < 0 || time > max;