Ejemplo n.º 1
1
  public void startApp() {
    // Create Record Store
    try {
      rs = RecordStore.openRecordStore("myrs", true);
    } catch (RecordStoreException e) {
    }

    dsp = Display.getDisplay(this);
    listMenu.setCommandListener(this);
    listMenu.addCommand(cmdExit);
    dsp.setCurrent(listMenu);
  }
Ejemplo n.º 2
0
  private void save2RS() {
    RecordStore rs = null;
    try {
      RecordStore.deleteRecordStore("score");
      rs = RecordStore.openRecordStore("score", true);

      try {
        for (int i = 0; i < 5; i++) {
          ByteArrayOutputStream bytes;
          DataOutputStream dataOut = new DataOutputStream(bytes = new ByteArrayOutputStream());
          ScoreItem item = (ScoreItem) list.elementAt(i);
          dataOut.writeUTF(item.name);
          dataOut.writeInt(item.points);
          dataOut.writeInt(item.level);
          dataOut.writeLong(item.date);
          byte[] byteA = bytes.toByteArray();
          rs.addRecord(byteA, 0, byteA.length);
        }
      } catch (IOException exp) {
        RecordStore.deleteRecordStore("score");
        System.out.println("XXXXXXXXXXXXXXXXXXXXXX");
      }
      // System.out.println("size of rs after saving: "+ rs.getNumRecords());
      rs.closeRecordStore();
    } catch (RecordStoreException exp) {
      System.out.println("fehler: " + exp.toString());
      exp.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  public void readRS() {
    RecordStore rs = null;
    try {
      rs = RecordStore.openRecordStore("score", true);
      byte[] byteA = new byte[100];

      list.removeAllElements();
      // System.out.println("size of list before reading out of rs: "+ list.size());
      for (int i = 1; i < 6; i++) {
        byteA = rs.getRecord(i);
        // System.out.println((char) byteA[0]);
        // System.out.println("1");
        ByteArrayInputStream bytes = new ByteArrayInputStream(byteA);
        // System.out.println("2");
        DataInputStream dataIn = new DataInputStream(bytes);
        // System.out.println("3");
        try {
          list.addElement(
              new ScoreItem(
                  dataIn.readUTF(), dataIn.readInt(), dataIn.readInt(), dataIn.readLong()));
        } catch (IOException exp) {
        }
      }
      // System.out.println("size of list after reading out of rs: "+ list.size());
      rs.closeRecordStore();
    } catch (RecordStoreException exp) {
      System.out.println("fehler: " + exp.toString());
      exp.printStackTrace();
    }
  }
Ejemplo n.º 4
0
 private void try2OpenRS() {
   try {
     RecordStore rs = RecordStore.openRecordStore("score", false);
     rs.closeRecordStore();
   } catch (RecordStoreNotFoundException exp) {
     // System.out.println("rs was empty");
     initFirstTimeRS();
   } catch (RecordStoreException exo) {
   }
 }
Ejemplo n.º 5
0
 private void initFirstTimeRS() {
   // System.out.println("test");
   list.removeAllElements();
   // System.out.println("size of list before first initiation: "+ list.size());
   list.addElement(new ScoreItem("Saban", 5000, 412, System.currentTimeMillis()));
   list.addElement(new ScoreItem("Osman", 2500, 380, System.currentTimeMillis()));
   list.addElement(new ScoreItem("Aslan", 500, 460, System.currentTimeMillis()));
   list.addElement(new ScoreItem("Moruk", 250, 120, System.currentTimeMillis()));
   list.addElement(new ScoreItem("Yabani", 100, 240, System.currentTimeMillis()));
   // System.out.println("size of list before after initiation: "+ list.size());
   try {
     RecordStore rs = null;
     rs = RecordStore.openRecordStore("score", true);
     rs.closeRecordStore();
     save2RS();
   } catch (RecordStoreException exp) {
   }
 }
Ejemplo n.º 6
0
  /** Get the settings the Manager saved for the user. */
  private void restoreSettings() {
    ByteArrayInputStream bas;
    DataInputStream dis;
    byte[] data;
    RecordStore settings = null;

    try {
      settings = RecordStore.openRecordStore(GraphicalInstaller.SETTINGS_STORE, false);

      data = settings.getRecord(1);
      if (data != null) {
        bas = new ByteArrayInputStream(data);
        dis = new DataInputStream(bas);
        defaultInstallListUrl = dis.readUTF();
      }

    } catch (RecordStoreException e) {
      if (Logging.REPORT_LEVEL <= Logging.WARNING) {
        Logging.report(
            Logging.WARNING, LogChannels.LC_AMS, "restoreSettings threw a RecordStoreException");
      }
    } catch (IOException e) {
      if (Logging.REPORT_LEVEL <= Logging.WARNING) {
        Logging.report(Logging.WARNING, LogChannels.LC_AMS, "restoreSettings threw an IOException");
      }
    } finally {
      if (settings != null) {
        try {
          settings.closeRecordStore();
        } catch (RecordStoreException e) {
          if (Logging.REPORT_LEVEL <= Logging.WARNING) {
            Logging.report(
                Logging.WARNING,
                LogChannels.LC_AMS,
                "closeRecordStore threw a RecordStoreException");
          }
        }
      }
    }
  }