示例#1
0
  /** Creates a new instance of ByteArrayString */
  public starIndex(FileAccessBase indexFile, starDict dict) {
    super(dict);
    if (Runtime.getRuntime().totalMemory() < 1024 * 1024) bufLen = 1024 * 8;
    FileAccessBase file = null;
    try {
      this.dict = dict;
      this.indexFile = indexFile;
      this.fileName = indexFile.getAbsolutePath();
      boolean indexOfIndexLoaded = false;
      file = FileFactory.openFileAccess(fileName + ".idx", true);

      try {
        if (file != null && file.isFile() && file.canRead()) {
          if (file.fileSize() > 0) {
            loadFromIndexOfIndexFile(file);
            indexOfIndexLoaded = true;
          }
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        if (file != null) {
          file.close();
          file = null;
        }
      }

      if (!indexOfIndexLoaded) {
        try {
          DictManager.getInstance().NotifyPromptStart("tuningindex");
          file = getIndexFile();
          loadFromIndexFile(file);
          // System.gc();
          saveToIndexOfIndexFile(fileName + ".idx");
          DictManager.getInstance().NotifyPromptEnd("tuningindex");
        } catch (Exception ex) {
          // System.out.println("Error While load index:" + ex.getMessage());
          ex.printStackTrace();
        }
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      try {
        if (file != null) {
          file.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }
示例#2
0
  protected boolean loadInfo() {
    String s = getLocation();
    s = s.substring(preifx.length());
    String[] tmp = com.teesoft.jfile.resource.resourceFileAccess.split(s, '/');
    dict = tmp[0];
    file = tmp[1];
    sparseSize = (int) SIZE;
    try {
      String url = OnlineInfo.dictsizeUrl + dict + "/" + file;
      FileAccessBase con = FileFactory.openFileAccess(url, false);
      byte[] buf = new byte[32];
      int len = con.read(buf);

      filesize = Long.parseLong(new String(buf, 0, len)); //
      // con.fileSize();
      setConnection(con);
    } catch (Exception ex) {
      return false;
    }
    return true;
  }
示例#3
0
 public FileAccessBase getIndexFile() throws IOException {
   if (indexFile == null) {
     indexFile = FileFactory.openFileAccess(fileName, true);
   }
   return indexFile;
 }