예제 #1
0
 protected ConfigManager() {
   // ConfigGroup general = new ConfigGroup("defaults","general");
   appName = "defaults";
   general = null;
   bookmarks = null;
   if (FileFactory.isMicroedition()) {
     this.maxCount = 5;
   } else {
     this.maxCount = 20;
   }
 }
예제 #2
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();
      }
    }
  }
예제 #3
0
 private synchronized void saveToIndexOfIndexFile(String fileName) throws IOException {
   FileAccessBase file = FileFactory.newFileAccess(fileName);
   if (file == null) {
     return;
   }
   if (!file.exists()) {
     file.create();
   }
   if (file.isFile() && file.canWrite()) {
     int writeBufLen = 256 + 1 + 16;
     byte[] buf = new byte[bufLen];
     int pos = 0;
     int ret = 0;
     int contentLength = 0;
     starIndex.putIntintoByte(this.bucketSize, 0, buf);
     // System.out.println("write " + wordList.size());
     file.write(buf, 0, 4);
     for (int i = 0; i < wordList.size(); i++) {
       starIndexItem item = (starIndexItem) wordList.elementAt(i);
       if (item.getBytes().length + 19 + pos < bufLen) {
         ByteArrayString.byteCopy(item.getBytes(), 0, buf, pos, item.getBytes().length);
         pos += item.getBytes().length;
         buf[pos] = 0;
         pos++;
         starIndex.putIntintoByte(item.getbucket(0).getStart(), pos, buf);
         pos += 4;
         starIndex.putIntintoByte(item.getbucket(0).getLength(), pos, buf);
         pos += 4;
         starIndex.putIntintoByte(item.getStart(), pos, buf);
         pos += 4;
         starIndex.putIntintoByte(item.getLength(), pos, buf);
         pos += 4;
       } else {
         file.write(buf, 0, pos);
         pos = 0;
         i--;
       }
     }
     if (pos != 0) {
       file.write(buf, 0, pos);
     }
     file.flush();
     file.close();
     buf = null;
   }
 }
예제 #4
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;
  }
예제 #5
0
 // disable autodiscover by default for phone
 public boolean getNoAutoDiscovery() {
   return getBooleanValue("NoAutoDiscovery", FileFactory.isMicroedition());
 }
예제 #6
0
 public boolean getPlaySoundDirectly() {
   return getBooleanValue("PlaySoundDirectly", !FileFactory.isMicroedition());
 }
예제 #7
0
 public FileAccessBase getIndexFile() throws IOException {
   if (indexFile == null) {
     indexFile = FileFactory.openFileAccess(fileName, true);
   }
   return indexFile;
 }