Exemplo n.º 1
0
  /**
   * called by the constructor, should set class level fields. Should throw runtime exception for
   * bad/incomplete data.
   *
   * @param in the stream to read from
   */
  public SupBookRecord(RecordInputStream in) {
    int recLen = in.remaining();

    field_1_number_of_sheets = in.readShort();

    if (recLen > SMALL_RECORD_SIZE) {
      // 5.38.1 External References
      _isAddInFunctions = false;

      field_2_encoded_url = in.readString();
      String[] sheetNames = new String[field_1_number_of_sheets];
      for (int i = 0; i < sheetNames.length; i++) {
        sheetNames[i] = in.readString();
      }
      field_3_sheet_names = sheetNames;
      return;
    }
    // else not 'External References'
    field_2_encoded_url = null;
    field_3_sheet_names = null;

    short nextShort = in.readShort();
    if (nextShort == TAG_INTERNAL_REFERENCES) {
      // 5.38.2 'Internal References'
      _isAddInFunctions = false;
    } else if (nextShort == TAG_ADD_IN_FUNCTIONS) {
      // 5.38.3 'Add-In Functions'
      _isAddInFunctions = true;
      if (field_1_number_of_sheets != 1) {
        throw new RuntimeException(
            "Expected 0x0001 for number of sheets field in 'Add-In Functions' but got ("
                + field_1_number_of_sheets
                + ")");
      }
    } else {
      throw new RuntimeException(
          "invalid EXTERNALBOOK code (" + Integer.toHexString(nextShort) + ")");
    }
  }