Example #1
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);
  }
Example #2
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();
    }
  }
Example #3
0
  public void showFirstRecord() {
    fmFirstRecord = new Form("First Record");
    String name = "Nenacetl jsem";
    int number = 0;
    try {
      byte[] record = rs.getRecord(1);
      ByteArrayInputStream buffer = new ByteArrayInputStream(record);
      DataInputStream dis = new DataInputStream(buffer);
      name = dis.readUTF();
      number = dis.readInt();
      dis.close();
    } catch (Exception e) {
    }

    fmFirstRecord.append(name + " " + String.valueOf(number));
    // fmFirstRecord.append(String.valueOf(number));
    fmFirstRecord.setCommandListener(this);
    fmFirstRecord.addCommand(cmdMenu);
    dsp.setCurrent(fmFirstRecord);
  }
  /**
   * Gets the JAR URL of the suite. This is only for the installer.
   *
   * @return URL of the JAR, never null, even in development environments
   */
  public String getJarUrl() {
    RandomAccessStream storage = new RandomAccessStream(classSecurityToken);
    DataInputStream storageStream;

    try {
      storage.connect(getStorageRoot() + Installer.JAR_URL_FILENAME, Connector.READ);

      // convert the JAR URL to UTF8 and write it to storage
      storageStream = storage.openDataInputStream();
      return storageStream.readUTF();
    } catch (Exception e) {
      // old installations did not have JAR URL's
      return "unknown";
    } finally {
      try {
        storage.disconnect();
      } catch (IOException e) {
        // ignore
      }
    }
  }
Example #5
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");
          }
        }
      }
    }
  }
Example #6
0
 public void editRecord(int record_num) {
   fmEditRecord = new Form("Edit Record");
   String name = "Nenacetl jsem";
   int number = 0;
   try {
     byte[] record = rs.getRecord(record_num);
     ByteArrayInputStream buffer = new ByteArrayInputStream(record);
     DataInputStream dis = new DataInputStream(buffer);
     name = dis.readUTF();
     number = dis.readInt();
     dis.close();
   } catch (Exception e) {
   }
   txfName = new TextField("Name", name, 10, TextField.ANY);
   txfNumber = new TextField("Number", String.valueOf(number), 10, TextField.NUMERIC);
   fmEditRecord.append(txfName);
   fmEditRecord.append(txfNumber);
   fmEditRecord.addCommand(cmdEdit);
   fmEditRecord.addCommand(cmdMenu);
   fmEditRecord.setCommandListener(this);
   dsp.setCurrent(fmEditRecord);
 }
  /**
   * Gets properites from a symbolically named installed package. The properties are the attributes
   * in the application descriptor and JAR Manifest.
   */
  private void getPropertiesFromStorage() {
    RandomAccessStream myStorage;
    int size;
    byte[] buffer;
    InputStream is;
    DataInputStream dis;
    String jadEncoding = null;

    myStorage = new RandomAccessStream(classSecurityToken);

    // Get the JAD encoding, if the server provided one
    try {
      myStorage.connect(storageRoot + Installer.JAD_ENCODING_FILENAME, Connector.READ);
      try {
        // convert the JAD encoding to UTF8 and write it to storage
        dis = myStorage.openDataInputStream();
        try {
          jadEncoding = dis.readUTF();
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // servers can choose the default encoding by not providing one
    }

    // Load .jad file
    bufferedJadProps = new JadProperties();
    try {
      myStorage.connect(storageRoot + Installer.JAD_FILENAME, Connector.READ);
      try {
        size = myStorage.getSizeOf();
        buffer = new byte[size];
        dis = myStorage.openDataInputStream();
        try {
          dis.readFully(buffer);
          is = new ByteArrayInputStream(buffer);

          bufferedJadProps.load(is, jadEncoding);

          buffer = null;
          is = null;
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // Jar only install
    }

    try {
      // Get Manifest file so we can buffer it
      myStorage.connect(storageRoot + Installer.MANIFEST_FILENAME, Connector.READ);
      try {
        size = myStorage.getSizeOf();
        buffer = new byte[size];
        dis = myStorage.openDataInputStream();
        try {
          dis.readFully(buffer);
          is = new ByteArrayInputStream(buffer);

          bufferedJarProps = new ManifestProperties();
          bufferedJarProps.load(is);

          buffer = null;
          is = null;
        } finally {
          dis.close();
        }
      } finally {
        myStorage.disconnect();
      }
    } catch (IOException e) {
      // ignore
    }
  }