/** * Builds the file words database file and the contents file for the on * disk dictionary. */ protected void buildNewDictionaryDatabase() throws FileNotFoundException, IOException { /* combine all dictionary files into one sorted file */ File sortedFile = buildSortedFile(); /* create the db for the sorted file */ buildCodeDb(sortedFile); sortedFile.delete(); /* build contents file */ buildContentsFile(); }
public void run() { try { buildNewDictionaryDatabase(); loadIndex(); ready = true; } catch (Exception e) { e.printStackTrace(); } } };
/** * Loads the index file from disk. The index file accelerates words lookup * into the dictionary db file. */ protected void loadIndex() throws IOException { index = new HashMap(); File idx = new File(db, FILE_INDEX); BufferedReader reader = new BufferedReader(new FileReader(idx)); String line; while ((line = reader.readLine()) != null) { String[] fields = split(line, ","); index.put(fields[0], new int[]{Integer.parseInt(fields[1]), Integer.parseInt(fields[2])}); } reader.close(); }
if (!this.db.exists()) db.mkdirs(); if (newDictionaryFiles()) { if (block) { buildNewDictionaryDatabase(); loadIndex(); ready = true; } else { loadIndex(); ready = true;
/** * Returns a list of words that have the same phonetic code. * @param code The phonetic code common to the list of words * @return A list of words having the same phonetic code */ public List getWords(String code) { Vector words = new Vector(); int[] posLen = getStartPosAndLen(code); if (posLen != null) { try { InputStream input = new FileInputStream(new File(db, FILE_DB)); input.skip(posLen[0]); byte[] bytes = new byte[posLen[1]]; input.read(bytes, 0, posLen[1]); input.close(); String data = new String(bytes); String[] lines = split(data, "\n"); for (int i = 0; i < lines.length; i++) { String[] s = split(lines[i], ","); if (s[0].equals(code)) words.addElement(s[1]); } } catch (Exception e) { e.printStackTrace(); } } return words; }
String word; while ((word = reader.readLine()) != null) { codeList.add(new CodeWord(this.getCode(word), word)); String thisCode = cw.getCode(); thisCode = getIndexCode(thisCode, codeList); String toWrite = cw.getCode() + "," + cw.getWord() + "\n"; byte[] bytes = toWrite.getBytes();
while ((line = reader.readLine()) != null) { String[] s = split(line, ","); contents.add(new FileSize(s[0], Integer.parseInt(s[1])));