Merge branch 'subtree'
[fanfix.git] / src / be / nikiroo / utils / Downloader.java
index b1ac56c0508300e6fee02eada0affd499117b7a8..4191d0aea0da85511e2741c50c2a6c83806f612f 100644 (file)
@@ -39,7 +39,7 @@ public class Downloader {
         *            the User-Agent to use to download the resources -- note that
         *            some websites require one, some actively blacklist real UAs
         *            like the one from wget, some whitelist a couple of browsers
-        *            only (!)
+        *            only (!) -- can be NULL
         */
        public Downloader(String UA) {
                this(UA, null);
@@ -52,7 +52,7 @@ public class Downloader {
         *            the User-Agent to use to download the resources -- note that
         *            some websites require one, some actively blacklist real UAs
         *            like the one from wget, some whitelist a couple of browsers
-        *            only (!)
+        *            only (!) -- can be NULL
         * @param cache
         *            the {@link Cache} to use for all access (can be NULL)
         */
@@ -281,7 +281,9 @@ public class Downloader {
                        }
                }
 
-               if (offline) {
+               String protocol = originalUrl == null ? null : originalUrl
+                               .getProtocol();
+               if (isOffline() && !"file".equalsIgnoreCase(protocol)) {
                        tracer.error("Downloader OFFLINE, cannot proceed to URL: " + url);
                        throw new IOException("Downloader is currently OFFLINE, cannot download: " + url);
                }
@@ -397,6 +399,11 @@ public class Downloader {
                                }
                        }
 
+                       if (in == null) {
+                               throw new IOException(
+                                               "Cannot retrieve the file after storing it in the cache (??)");
+                       }
+                       
                        return in;
                } catch (IOException e) {
                        throw new IOException(String.format(
@@ -426,7 +433,9 @@ public class Downloader {
                        conn.setRequestProperty("Cookie", cookies);
                }
 
-               conn.setRequestProperty("User-Agent", UA);
+               if (UA != null) {
+                       conn.setRequestProperty("User-Agent", UA);
+               }
                conn.setRequestProperty("Accept-Encoding", "gzip");
                conn.setRequestProperty("Accept", "*/*");
                conn.setRequestProperty("Charset", "utf-8");