/**
   * Reads and parses the contents of a shapefile record from a specified buffer. The buffer's
   * current position must be the start of the record and will be the start of the next record when
   * the constructor returns.
   *
   * @param shapefile the containing {@link Shapefile}.
   * @param buffer the shapefile record {@link java.nio.ByteBuffer} to read from.
   */
  protected void readFromBuffer(Shapefile shapefile, ByteBuffer buffer) {
    // Read record number and record length - big endian.
    buffer.order(ByteOrder.BIG_ENDIAN);
    this.recordNumber = buffer.getInt();
    this.contentLengthInBytes = buffer.getInt() * 2;

    // Read shape type - little endian
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    int type = buffer.getInt();
    String shapeType = shapefile.getShapeType(type);
    this.validateShapeType(shapefile, shapeType);

    this.shapeType = shapeType;
    this.shapeFile = shapefile;

    this.doReadFromBuffer(shapefile, buffer);
  }
  /**
   * Constructs a record instance from the given {@link java.nio.ByteBuffer}. The buffer's current
   * position must be the start of the record, and will be the start of the next record when the
   * constructor returns.
   *
   * @param shapeFile the parent {@link Shapefile}.
   * @param buffer the shapefile record {@link java.nio.ByteBuffer} to read from.
   * @throws IllegalArgumentException if any argument is null or otherwise invalid.
   * @throws gov.nasa.worldwind.exception.WWRuntimeException if the record's shape type does not
   *     match that of the shapefile.
   */
  public ShapefileRecord(Shapefile shapeFile, ByteBuffer buffer) {
    if (shapeFile == null) {
      String message = Logging.getMessage("nullValue.ShapefileIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (buffer == null) {
      String message = Logging.getMessage("nullValue.BufferIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Save the buffer's current position.
    int pos = buffer.position();
    try {
      this.readFromBuffer(shapeFile, buffer);
    } finally {
      // Move to the end of the record.
      buffer.position(pos + this.contentLengthInBytes + RECORD_HEADER_LENGTH);
    }
  }