Exemplo n.º 1
0
  /**
   * How many times do the subfields of this record repeat? This will always be one for
   * non-repeating fields.
   *
   * @return The number of times that the subfields of this record occur in this record. This will
   *     be one for non-repeating fields.
   */
  public int getRepeatCount() {
    if (!poDefn.isRepeating()) {
      return 1;
    }

    /* -------------------------------------------------------------------- */
    /* The occurrence count depends on how many copies of this */
    /* field's list of subfields can fit into the data space. */
    /* -------------------------------------------------------------------- */
    if (poDefn.getFixedWidth() != 0) {
      return pachData.length / poDefn.getFixedWidth();
    }

    /* -------------------------------------------------------------------- */
    /* Note that it may be legal to have repeating variable width */
    /* subfields, but I don't have any samples, so I ignore it for */
    /* now. */
    /*                                                                      */
    /*
     * The file data/cape_royal_AZ_DEM/1183XREF.DDF has a
     * repeating
     */
    /* variable length field, but the count is one, so it isn't */
    /* much value for testing. */
    /* -------------------------------------------------------------------- */
    int iOffset = 0;
    int iRepeatCount = 1;
    MutableInt nBytesConsumed = new MutableInt(0);

    while (true) {
      for (int iSF = 0; iSF < poDefn.getSubfieldCount(); iSF++) {
        DDFSubfieldDefinition poThisSFDefn = poDefn.getSubfieldDefn(iSF);

        if (poThisSFDefn.getWidth() > pachData.length - iOffset) {
          nBytesConsumed.value = poThisSFDefn.getWidth();
        } else {
          byte[] tempData = new byte[pachData.length - iOffset];
          System.arraycopy(pachData, iOffset, tempData, 0, tempData.length);
          poThisSFDefn.getDataLength(tempData, tempData.length, nBytesConsumed);
        }

        iOffset += nBytesConsumed.value;
        if (iOffset > pachData.length) {
          return iRepeatCount - 1;
        }
      }

      if (iOffset > pachData.length - 2) return iRepeatCount;

      iRepeatCount++;
    }
  }