vgritsenko 2003/08/14 20:10:06
Modified: java/src/org/apache/xindice/util FileCache.java Log: Improve exception handling in Filers. Add fault code DBE_CANNOT_READ in addition to _DROP and _CREATE. Use these fault codes consistently in all filers. Revision Changes Path 1.6 +23 -26 xml-xindice/java/src/org/apache/xindice/util/FileCache.java Index: FileCache.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/util/FileCache.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- FileCache.java 9 Aug 2003 05:01:55 -0000 1.5 +++ FileCache.java 15 Aug 2003 03:10:06 -0000 1.6 @@ -61,6 +61,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.util.Map; import java.util.WeakHashMap; @@ -70,7 +71,11 @@ * @version CVS $Revision$, $Date$ */ public class FileCache { - private Map cache = new WeakHashMap(); // of FileCacheInfo + + /** + * Caches FileCacheInfo objects. Keys are File objects. + */ + private final Map cache = new WeakHashMap(); public FileCache() { } @@ -94,36 +99,28 @@ || (file.lastModified() != finfo.lastModified); } - public final byte[] getFile(String name) { + public final byte[] getFile(String name) throws IOException { return getFile(new File(name)); } - public final byte[] getFile(File file) { - boolean reload = true; - FileCacheInfo finfo = (FileCacheInfo) cache.get(file); - long lastmod = file.lastModified(); + public final byte[] getFile(File file) throws IOException { if (!file.exists()) { return null; } - - if (finfo != null) { - reload = (lastmod != finfo.lastModified); - } - - if (reload) { - try { - FileInputStream fis = new FileInputStream(file); - byte[] content = new byte[fis.available()]; - fis.read(content); - fis.close(); - finfo = new FileCacheInfo(file, lastmod, content); - cache.put(file, finfo); - return content; - } catch (Exception e) { - return null; - } - } else + + FileCacheInfo finfo = (FileCacheInfo) cache.get(file); + long lastmod = file.lastModified(); + if (finfo == null || finfo.lastModified != lastmod) { + FileInputStream fis = new FileInputStream(file); + byte[] content = new byte[fis.available()]; + fis.read(content); + fis.close(); + finfo = new FileCacheInfo(file, lastmod, content); + cache.put(file, finfo); + return content; + } else { return finfo.content; + } } /**