X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FImage.java;h=6edc1051ab7b910c0b47733407c99d804a08a8fe;hb=82fcfcde9722e9e3b3eb713cf1f2bcb35fefaa7e;hp=3a89d29d4887e0121107871af39d660c4ca041c3;hpb=59864f77f0b8d5a57f479152a3131093544af6b2;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/Image.java b/src/be/nikiroo/utils/Image.java index 3a89d29..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(); @@ -100,7 +101,7 @@ public class Image implements Closeable { * @return the Base64 representation */ public String toBase64() { - return new String(Base64.encodeBytes(getData())); + return Base64.encodeBytes(getData()); } /** @@ -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; + } }