downloader: prepare offline mode
authorNiki Roo <niki@nikiroo.be>
Tue, 17 Sep 2019 06:24:34 +0000 (08:24 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 17 Sep 2019 06:24:34 +0000 (08:24 +0200)
libs/nikiroo-utils-5.0.0-dev-sources.jar [new file with mode: 0644]
libs/nikiroo-utils-5.0.0-sources.jar [deleted file]
src/be/nikiroo/fanfix/DataLoader.java
src/be/nikiroo/fanfix/test/Test.java

diff --git a/libs/nikiroo-utils-5.0.0-dev-sources.jar b/libs/nikiroo-utils-5.0.0-dev-sources.jar
new file mode 100644 (file)
index 0000000..3a29484
Binary files /dev/null and b/libs/nikiroo-utils-5.0.0-dev-sources.jar differ
diff --git a/libs/nikiroo-utils-5.0.0-sources.jar b/libs/nikiroo-utils-5.0.0-sources.jar
deleted file mode 100644 (file)
index f0364c1..0000000
Binary files a/libs/nikiroo-utils-5.0.0-sources.jar and /dev/null differ
index d342580614c4a8441efcd967ad4ce37ed9c9879c..3e0e7704e8e93068d93b7454a25e7f5fffb311f1 100644 (file)
@@ -28,6 +28,7 @@ public class DataLoader {
        private Downloader downloader;
        private Downloader downloaderNoCache;
        private Cache cache;
+       private boolean offline;
 
        /**
         * Create a new {@link DataLoader} object.
@@ -69,6 +70,41 @@ public class DataLoader {
                downloaderNoCache = downloader;
                cache = new CacheMemory();
        }
+       
+       /**
+        * This {@link Downloader} is forbidden to try and connect to the network.
+        * <p>
+        * If TRUE, it will only check the cache (even in no-cache mode!).
+        * <p>
+        * Default is FALSE.
+        * 
+        * @return TRUE if offline
+        */
+       public boolean isOffline() {
+               return offline;
+       }
+       
+       /**
+        * This {@link Downloader} is forbidden to try and connect to the network.
+        * <p>
+        * If TRUE, it will only check the cache (even in no-cache mode!).
+        * <p>
+        * Default is FALSE.
+        * 
+        * @param offline TRUE for offline, FALSE for online
+        */
+       public void setOffline(boolean offline) {
+               this.offline = offline;
+               downloader.setOffline(offline);
+               downloaderNoCache.setOffline(offline);
+               
+               // If we don't, we cannot support no-cache using code in OFFLINE mode
+               if (offline) {
+                       downloaderNoCache.setCache(cache);
+               } else {
+                       downloaderNoCache.setCache(null);
+               }
+       }
 
        /**
         * The traces handler for this {@link Cache}.
index 05edcb0965cbbbca08b9ab770ce62b84273dda22..8ca8b7ca1f09a73fc09e15f7e13ad25f0c7ec9ee 100644 (file)
@@ -49,6 +49,7 @@ public class Test extends TestLauncher {
         */
        static public void main(String[] args) throws IOException {
                Instance.init();
+               //Instance.getCache().setOffline(true);
                
                int result = 0;
                tempFiles = new TempFiles("fanfix-test");