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();
      }
    }
  }
Exemple #2
0
  public void save() throws RecordStoreException {
    RecordStore rs = null;
    RecordEnumeration re = null;
    try {
      rs = RecordStore.openRecordStore(mRecordStoreName, true);
      re = rs.enumerateRecords(null, null, false);

      // First remove all records, a little clumsy.
      while (re.hasNextElement()) {
        int id = re.nextRecordId();
        rs.deleteRecord(id);
      }

      // Now save the preferences records.
      Enumeration keys = mHashtable.keys();
      while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = get(key);
        String pref = key + "|" + value;
        byte[] raw = pref.getBytes();
        rs.addRecord(raw, 0, raw.length);
      }
    } finally {
      if (re != null) re.destroy();
      if (rs != null) rs.closeRecordStore();
    }
  }
  /**
   * 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();
      }
    }
  }
Exemple #4
0
  public RMSOutputStream(String storename) throws IOException {
    super();
    rsname = storename;

    try {
      rs = RecordStore.openRecordStore(rsname, true);
      // clear up any old content!
      RecordEnumeration records = rs.enumerateRecords(null, null, false);
      while (records.hasNextElement()) {
        rs.deleteRecord(records.nextRecordId());
      }
      records.destroy();
    } catch (Exception e) {
      throw new IOException(e.toString());
    }
  }
Exemple #5
0
  private void load() throws RecordStoreException {
    RecordStore rs = null;
    RecordEnumeration re = null;

    try {
      rs = RecordStore.openRecordStore(mRecordStoreName, true);
      re = rs.enumerateRecords(null, null, false);
      while (re.hasNextElement()) {
        byte[] raw = re.nextRecord();
        String pref = new String(raw);
        // Parse out the name.
        int index = pref.indexOf('|');
        String name = pref.substring(0, index);
        String value = pref.substring(index + 1);
        put(name, value);
      }
    } finally {
      if (re != null) re.destroy();
      if (rs != null) rs.closeRecordStore();
    }
  }