Exemple #1
0
  // set offset for Applications Settings for each record and generate Applications Setting Table
  public void genenerateApplicationsSettingsTable() throws Exception {
    int totalDataLength = 0;
    String err = ""; // collected all errors for setBlockApplicationsForOneRecord();

    // set offset and binary data for Applications Settings for each record
    for (int i = 0; i < arraySortedRecords.length; i++) {
      try {
        arraySortedRecords[i].application_settings_offset = totalDataLength;
        int currDataLength = setBlockApplicationsForOneRecord(arraySortedRecords[i]);
        totalDataLength += currDataLength;
      } catch (Exception ex) {
        err += ex.getMessage() + "\n";
      }
    }
    if (err.length() > 0) {
      throw new Exception(err);
    }

    // create appl settings table
    byte[] b;
    applicationsSettingsTable = new BlockTable(totalDataLength);
    for (int i = 0; i < arraySortedRecords.length; i++) {
      b = arraySortedRecords[i].application_settings;
      applicationsSettingsTable.appendData(b);
      arraySortedRecords[i].application_settings = null; // release memory !!!!

      //////////////// -- test --///////////////////
      /* int iii = ( ( ( (int) b[0]) & 0xff) << 16) +
          ( ( ( (int) b[1]) & 0xff) << 8) + ( ( (int) b[2]) & 0xff);
      System.out.println(arraySortedRecords[i].key.replaceAll(":", "_") +
                         " :  " + b.length + "  iii= " + (iii >>> 1) +
                         "  flag: " + (iii & 1));*/
      ///////////////////// -- end test-- ///////////////////

    }

    Validator.validateMaxAppsSettingsLength(applicationsSettingsTable.length);
    int lastOffset = arraySortedRecords[arraySortedRecords.length - 1].application_settings_offset;
    Validator.validateMaxAppsSettingsOffset(lastOffset);
  }
Exemple #2
0
  // generate operators names table with name length. assign offset for each record
  public static void genenerateOperatorsNamesTable() throws Exception {
    // operatorsNamesBytes
    HashMap hashNames = new HashMap();
    String name;

    for (int i = 0; i < arraySortedRecords.length; i++) {
      name = arraySortedRecords[i].operator_name;

      if (hashNames.containsKey(name)) {
        Integer offset = (Integer) hashNames.get(name);
        arraySortedRecords[i].operator_name_offset = offset.intValue();
      } else {

        byte[] nameByteArr = name.getBytes();
        // since operatorsNamesBytes.length are always even...
        int half_offset = operatorsNamesBytes.length() / 2;
        Validator.validateOperatorNameOffset(half_offset); // validate half_offset
        arraySortedRecords[i].operator_name_offset = half_offset;

        int nameLength =
            nameByteArr.length + 1; // length of name  + one byte to present this length.
        operatorsNamesBytes.addByte((byte) nameLength);
        operatorsNamesBytes.addBytes(nameByteArr);
        if ((operatorsNamesBytes.length() % 2) > 0) {
          // add one dummy byte to make it even
          operatorsNamesBytes.addByte((byte) 0);
        }
        hashNames.put(name, new Integer(half_offset));
      }
    }

    // create operators Names Table
    operatorsNamesTable = new BlockTable(operatorsNamesBytes.length());
    operatorsNamesTable.appendData(operatorsNamesBytes.getBytes());

    Validator.validateOperatorNamesTableSize(operatorsNamesTable.length);
  }