Example #1
0
 /**
  * Add list of word to idx, dict file, modify size .ifo file.
  *
  * @param pWord word that is added
  * @param pMean word mean
  * @return true if success
  */
 public boolean addListOfWords(String[] pWord, String[] pMean) {
   if (pWord.length != pMean.length || pWord.length == 0) {
     return false;
   }
   try {
     for (int i = 0; i < pWord.length; i++) {
       String strLwrWord = pWord[i].toLowerCase();
       int pos = (int) idxFile.findIndexForWord(strLwrWord);
       boolean bExist = false;
       if (pos < (int) idxFile.getLongWordCount()) {
         if (strLwrWord.compareTo(((WordEntry) idxFile.getEntryList().get(pos)).getStrLwrWord())
             == 0) {
           bExist = true;
         }
       }
       long nextOffset = dictFile.addData(pMean[i]);
       if (nextOffset >= 0) {
         if (!bExist) {
           idxFile.addEntry(pWord[i], nextOffset, pMean[i].length(), pos);
         } else {
           WordEntry tempEntry = idxFile.getEntryList().get(pos);
           tempEntry.setLongOffset(nextOffset);
           tempEntry.setLongSize(pMean[i].length());
         }
       }
     }
     idxFile.write();
     ifoFile.setLongIdxFileSize(idxFile.getLongIdxFileSize());
     ifoFile.setLongWordCount(idxFile.getLongWordCount());
     ifoFile.write();
   } catch (Exception ex) {
     return false;
   }
   return true;
 }
Example #2
0
  /** load index file and info file. */
  public void reLoad() {
    boolAvailable = false;
    ifoFile.reload();
    idxFile.reload();

    if (ifoFile.isBoolIsLoaded() && idxFile.isLoaded()) {
      boolAvailable = true;
    }
  }
Example #3
0
  public static StarDict loadDict(String url) {
    File file = new File(url);
    String ifoFilePath;

    IfoFile ifoFile = null;
    IdxFile idxFile = null;
    DictFile dictFile = null;

    if (!file.isDirectory()) {
      String filePathNoExt = getFileNameWithoutExtension(url);
      //            LOG.debug("filePathNoExt=" + filePathNoExt);

      ifoFilePath = filePathNoExt + ".ifo";
      if (new File(ifoFilePath).isFile()) {
        ifoFile = new IfoFile(ifoFilePath);
      } else {
        return null;
      }

      idxFile =
          new IdxFile(
              filePathNoExt + ".idx", ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
      dictFile = new DictFile(filePathNoExt + ".dict");
    } else {
      String[] list = file.list();

      for (int i = list.length - 1; i >= 0; i--) {
        String extension = getExtension(list[i]);
        String path = url + File.separator + list[i];
        if (extension.equals("ifo")) {
          ifoFile = new IfoFile(path);
        } else if (extension.equals("idx")) {
          idxFile = new IdxFile(path, ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
        } else if (extension.equals("dict")) {
          dictFile = new DictFile(path);
        } else {
          continue;
        }
      }
    }

    if ((ifoFile == null) || (idxFile == null) || (dictFile == null)) {
      return null;
    }

    StarDict dict = new StarDict(ifoFile, idxFile, dictFile);
    return dict;
  }
Example #4
0
  /**
   * Constructor to load dictionary with given path.
   *
   * @param url Path of one of stardict file or Path of folder contains stardict files
   */
  public StarDict(String url) {
    File file = new File(url);

    if (!file.isDirectory()) {
      strURL = getFileNameWithoutExtension(url);
      Log.d(LOG_TAG, "strURL=" + strURL);
      ifoFile = new IfoFile(strURL + ".ifo");
      idxFile =
          new IdxFile(strURL + ".idx", ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
      dictFile = new DictFile(strURL + ".dict");
      Log.d(LOG_TAG, "done " + ifoFile.isBoolIsLoaded() + " " + idxFile.isLoaded() + " ");
    } else {
      String[] list = file.list();
      strURL = url;
      Log.d(LOG_TAG, "strURL=" + strURL);
      for (int i = list.length - 1; i >= 0; i--) {
        String extension = getExtension(list[i]);
        String path = url + File.separator + list[i];
        if (extension.equals("ifo")) {
          ifoFile = new IfoFile(path);
        } else if (extension.equals("idx")) {
          idxFile = new IdxFile(path, ifoFile.getLongWordCount(), ifoFile.getLongIdxFileSize());
        } else if (extension.equals("dict")) {
          dictFile = new DictFile(path);
        }
      }
    }

    if (ifoFile.isBoolIsLoaded() && idxFile.isLoaded()) {
      boolAvailable = true;
    }
  }
Example #5
0
 /**
  * get book version.
  *
  * @return version of a dictionary
  */
 public String getDictVersion() {
   return ifoFile.getStrVersion();
 }
Example #6
0
 /**
  * get book name of dictionary.
  *
  * @return Book name
  */
 public String getDictName() {
   return ifoFile.getStrBookname().replace("\r", "").trim();
 }