// Find the config file and fetch its contents as Properties
Resource config = new Resource(CONFIG_FILE);
Properties props = new Properties();
props.load(config.getInputStream());
// Determine the source dir of the config file and look for a cache file
// next to it containing a full representation of our program state.
// If we find a cache file and it is current, load and return that data.
if (config.getDirectory() != null) {
File cache = new File(config.getDirectory(), CACHE_FILE);
if (cache.exists() &&
cache.lastModified() >= config.lastModified()) {
try {
return loadCache(new FileInputStream(cache));
}
catch (IOException ignored) { }
}
}
// We get here if there's no cache file or it's stale and we need to do a
// full reload. Locate the name of the raw data file from the config file
// and return its contents using Resource.
Resource data = new Resource(props.getProperty("data.file"));
return loadData(data.getInputStream());