X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FCache.java;h=ff2859eb44403062a5186abd78aa0233316a4926;hb=7194ac50b29064a013f177fc9cfc5aaa131a8ec4;hp=dbe2020188ec44ae2dfd673529f49a8e6abdf462;hpb=223aa0d4e40e5f3ba9f7b9a7a2165aaff4bf7494;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/Cache.java b/src/be/nikiroo/utils/Cache.java index dbe2020..ff2859e 100644 --- a/src/be/nikiroo/utils/Cache.java +++ b/src/be/nikiroo/utils/Cache.java @@ -1,13 +1,14 @@ package be.nikiroo.utils; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Date; +import be.nikiroo.utils.streams.MarkableFileInputStream; + /** * A generic cache system, with special support for {@link URL}s. *

@@ -263,7 +264,7 @@ public class Cache { if (cached.exists() && cached.isFile() && (allowTooOld || !isOld(cached, stable))) { try { - return new MarkableFileInputStream(new FileInputStream(cached)); + return new MarkableFileInputStream(cached); } catch (FileNotFoundException e) { return null; } @@ -319,8 +320,9 @@ public class Cache { * in case of I/O error */ private void save(InputStream in, File cached) throws IOException { - clean(true, dir, 10); + // We delete AFTER so not to remove the subdir we will use... IOUtils.write(in, cached); + clean(true, dir, 10); } /**