Loads the index @throws DictionaryException
()
| 71 | * @throws DictionaryException |
| 72 | */ |
| 73 | private DictEntries load() throws DictionaryException { |
| 74 | if (indexEntries != null) { |
| 75 | final DictEntries entries = (DictEntries) indexEntries.get(); |
| 76 | |
| 77 | if (entries != null) { |
| 78 | |
| 79 | /* |
| 80 | * Dict already loaded. |
| 81 | */ |
| 82 | return entries; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | try { |
| 87 | file.seek(indexPosition); |
| 88 | |
| 89 | final int wordsCount = file.readInt(); |
| 90 | |
| 91 | final char[][] indexEntryNames = new char[wordsCount][]; |
| 92 | final int[] indexEntryPositions = new int[wordsCount]; |
| 93 | |
| 94 | for (int i = 0; i < wordsCount; i++) { |
| 95 | indexEntryNames[i] = file.readUTFchars(); |
| 96 | indexEntryPositions[i] = file.readInt(); |
| 97 | } |
| 98 | |
| 99 | DictEntries entries = |
| 100 | new DictEntries(indexEntryNames, indexEntryPositions); |
| 101 | |
| 102 | indexEntries = new WeakReference(entries); |
| 103 | return entries; |
| 104 | } catch (Exception e) { |
| 105 | throw new DictionaryException("Cannot load dictionary index"); |
| 106 | } catch (OutOfMemoryError e) { |
| 107 | throw new DictionaryException("Out of memory while loading index"); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Unloads the index, thus freeing memory. |
no test coverage detected