MCPcopy Index your code
hub / github.com/dumbledore/AlbiteREADER / load

Method load

src/org/albite/dictionary/Dictionary.java:73–109  ·  view source on GitHub ↗

Loads the index @throws DictionaryException

()

Source from the content-addressed store, hash-verified

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.

Callers 2

lookUpMethod · 0.95
getDefinitionMethod · 0.95

Calls 4

getMethod · 0.80
readIntMethod · 0.80
readUTFcharsMethod · 0.80
seekMethod · 0.45

Tested by

no test coverage detected