Пример #1
0
  private void load() throws RecordStoreException {
    RecordStore recordStore = null;
    RecordEnumeration recordEnumeration = null;

    try {
      recordStore = RecordStore.openRecordStore(_recordStoreName, true);
      recordEnumeration = recordStore.enumerateRecords(null, null, false);

      while (recordEnumeration.hasNextElement()) {
        byte[] raw = recordEnumeration.nextRecord();
        String entry = new String(raw);

        /* Parse name and value for a preference entry. */
        int index = entry.indexOf('=');
        String name = entry.substring(0, index);
        String value = entry.substring(index + 1);
        put(name, value);
      }
    } finally {
      if (recordEnumeration != null) {
        recordEnumeration.destroy();
      }

      if (recordStore != null) {
        recordStore.closeRecordStore();
      }
    }
  }
Пример #2
0
  /**
   * Saves current settings to the Record Management Store.
   *
   * @throws RecordStoreException if error occured while accessing the Record Management Store.
   */
  public void save() throws RecordStoreException {
    RecordStore recordStore = null;
    RecordEnumeration recordEnumeration = null;

    try {
      recordStore = RecordStore.openRecordStore(_recordStoreName, true);
      recordEnumeration = recordStore.enumerateRecords(null, null, false);

      /* Remove all records first. */
      while (recordEnumeration.hasNextElement()) {
        int id = recordEnumeration.nextRecordId();
        recordStore.deleteRecord(id);
      }

      /* Now save the preferences. */
      IStringEnumeration keys = _hashtable.keys();

      while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        String value = get(key);
        String entry = key + "=" + value;
        byte[] raw = entry.getBytes();
        recordStore.addRecord(raw, 0, raw.length);
      }
    } finally {
      if (recordEnumeration != null) {
        recordEnumeration.destroy();
      }

      if (recordStore != null) {
        recordStore.closeRecordStore();
      }
    }
  }