X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FImage.java;fp=src%2Fbe%2Fnikiroo%2Futils%2FImage.java;h=6edc1051ab7b910c0b47733407c99d804a08a8fe;hp=4eacdac8f0b15ae08bb09767a0145032080d9965;hb=82fcfcde9722e9e3b3eb713cf1f2bcb35fefaa7e;hpb=ce3972ea1a7083d1f8ef17463fb48c5bfa7ebf73 diff --git a/src/be/nikiroo/utils/Image.java b/src/be/nikiroo/utils/Image.java index 4eacdac..6edc105 100644 --- a/src/be/nikiroo/utils/Image.java +++ b/src/be/nikiroo/utils/Image.java @@ -13,6 +13,7 @@ import java.io.InputStream; * @author niki */ public class Image implements Closeable { + static private File tempRoot; static private TempFiles tmpRepository; static private long count = 0; static private Object lock = new Object(); @@ -143,7 +144,7 @@ public class Image implements Closeable { private File getTemporaryFile() throws IOException { synchronized (lock) { if (tmpRepository == null) { - tmpRepository = new TempFiles("images"); + tmpRepository = new TempFiles(tempRoot, "images"); count = 0; } @@ -152,4 +153,23 @@ public class Image implements Closeable { return tmpRepository.createTempFile("image"); } } + + /** + * Change the temporary root directory used by the program. + *

+ * Caution: the directory will be owned by the system, all its files + * now belong to us (and will most probably be deleted). + *

+ * Note: it may take some time until the new temporary root is used, we + * first need to make sure the previous one is not used anymore (i.e., we + * must reach a point where no unclosed {@link Image} remains in memory) to + * switch the temporary root. + * + * @param root + * the new temporary root, which will be owned by the + * system + */ + public static void setTemporaryFilesRoot(File root) { + tempRoot = root; + } }