CacheUtil throws IOExceptions now if there were issues reading file

info (that is to be cached)
This commit is contained in:
nathan 2017-07-09 00:01:15 +02:00
parent f464b871a2
commit 48e3f0d784
1 changed files with 11 additions and 1 deletions

View File

@ -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