Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed recursion and the checked SecurityException from getDictionary
  • Loading branch information
dren-dk committed Mar 6, 2013
1 parent ce742b7 commit 745f95a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/dk/dren/hunspell/Hunspell.java
Expand Up @@ -210,19 +210,29 @@ public static String libNameBare() throws UnsupportedOperationException {
* and /dict/da_DK.aff get loaded
*/
public Dictionary getDictionary(String baseFileName)
throws FileNotFoundException, SecurityException, UnsupportedEncodingException {
throws FileNotFoundException, UnsupportedEncodingException {

// Check the last modified date to detect if the dictionary files have changed and reload if they have.
File dicFile = new File(baseFileName + ".dic");
File affFile = new File(baseFileName + ".aff");
Long lastModified = new Long(dicFile.lastModified() + affFile.lastModified());

// TODO: Perhaps we should limit the frequency of stat'ing these files as we're spamming system calls this way:
Long lastModified;

try {
lastModified = new Long(dicFile.lastModified() + affFile.lastModified());
} catch (SecurityException e) {
// Meh, there's nothing we can do about it, but it should never happen anyway.
lastModified = new Long(0);
}

if (modMap.containsKey(baseFileName) && modMap.get(baseFileName) != lastModified) {
destroyDictionary(baseFileName);
}

if (map.containsKey(baseFileName)) {
if(modMap.get(baseFileName) != lastModified) {
destroyDictionary(baseFileName);
return getDictionary(baseFileName);
} else {
return map.get(baseFileName);
}
return map.get(baseFileName);

} else {
Dictionary d = new Dictionary(baseFileName);
map.put(baseFileName, d);
Expand Down

0 comments on commit 745f95a

Please sign in to comment.