From 48e3f0d7844c0556f8e0ec8cfc02260060b844bf Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 9 Jul 2017 00:01:15 +0200 Subject: [PATCH] CacheUtil throws IOExceptions now if there were issues reading file info (that is to be cached) --- src/dorkbox/util/CacheUtil.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dorkbox/util/CacheUtil.java b/src/dorkbox/util/CacheUtil.java index e9bddd3..69931e5 100644 --- a/src/dorkbox/util/CacheUtil.java +++ b/src/dorkbox/util/CacheUtil.java @@ -185,6 +185,8 @@ class CacheUtil { /** * Saves the name of the file in a cache, based on name. If cacheName is NULL, it will use the file's name. + * + * @return the newly create cache file, or an IOException if there were problems */ public static synchronized File save(String cacheName, final String fileName) throws IOException { @@ -203,7 +205,11 @@ class CacheUtil { // is file sitting on drive File iconTest = new File(fileName); - if (iconTest.isFile() && iconTest.canRead()) { + if (iconTest.isFile()) { + if (!iconTest.canRead()) { + throw new IOException("File exists but unable to read source file " + fileName); + } + // have to copy the resource to the cache FileUtil.copyFile(iconTest, newFile); @@ -213,6 +219,10 @@ class CacheUtil { // suck it out of a URL/Resource (with debugging if necessary) final URL systemResource = LocationResolver.getResource(fileName); + if (systemResource == null) { + throw new IOException("Unable to load URL resource " + fileName); + } + InputStream inStream = systemResource.openStream(); // saves the file into our temp location, uses HASH of cacheName