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();
      }
    }
  }
  /**
   * 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();
      }
    }
  }
Beispiel #3
0
  public void showAllRecordForm() {
    fmAllRecords = new Form("All records");
    try {
      RecordEnumeration recEnum = rs.enumerateRecords(null, null, false);
      while (recEnum.hasNextElement()) {
        try {
          // System.out.println(new String(recEnum.nextRecord()));
          String name = "Nenacetl jsem";
          int number = 0;
          try {
            byte[] record = recEnum.nextRecord();
            ByteArrayInputStream buffer = new ByteArrayInputStream(record);
            DataInputStream dis = new DataInputStream(buffer);
            name = dis.readUTF();
            number = dis.readInt();
            dis.close();
          } catch (Exception e) {
          }

          fmAllRecords.append(name + " " + String.valueOf(number) + "\n");
        } catch (Exception e) {
          System.out.println(e.getMessage());
        }

        //
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
    fmAllRecords.addCommand(cmdMenu);
    fmAllRecords.setCommandListener(this);
    dsp.setCurrent(fmAllRecords);
  }
Beispiel #4
0
  /**
   * This will populate the imageInfo hashtable with the ImageInfo object, referenced by label name
   * and populate the imageTable hashtable with Image objects referenced by the RMS record Id
   *
   * @throws PersistenceMechanismException
   */
  public MediaData[] loadMediaDataFromRMS(String recordName)
      throws PersistenceMechanismException, InvalidImageDataException {
    Vector mediaVector = new Vector();

    try {
      String infoStoreName = info_label + recordName;
      RecordStore infoStore = RecordStore.openRecordStore(infoStoreName, false);
      RecordEnumeration isEnum = infoStore.enumerateRecords(null, null, false);

      while (isEnum.hasNextElement()) {
        // Get next record
        int currentId = isEnum.nextRecordId();
        byte[] data = infoStore.getRecord(currentId);

        // Convert the data from a byte array into our ImageData
        // (metadata) object
        MediaData iiObject = getMediaFromBytes(data);

        // Add the info to the metadata hashtable
        String label = iiObject.getMediaLabel();
        mediaVector.addElement(iiObject);
        getMediaInfoTable().put(label, iiObject);
      }
      infoStore.closeRecordStore();

    } catch (RecordStoreException rse) {
      throw new PersistenceMechanismException(rse);
    }

    // Re-copy the contents into a smaller array
    MediaData[] labelArray = new MediaData[mediaVector.size()];
    mediaVector.copyInto(labelArray);
    return labelArray;
  }
Beispiel #5
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();
    }
  }
Beispiel #6
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());
    }
  }
Beispiel #7
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();
    }
  }