示例#1
0
  /**
   * This method loads all of the fields in the mapTable argument via the dis stream, which is setup
   * at the proper location.
   *
   * @param dis Input stream reading from the .dbf file.
   * @param mapTable The dbf table being loaded.
   * @throws IOException Thrown when the stream fails.
   */
  private void loadFields(DataInputStream dis, DBFTable mapTable) throws IOException {
    // NUMBER OF FIELDS (COLUMNS) IN THE TABLE
    int numFields = (mapTable.getPositionOfFirstDataRecorded() - 32 - 2 + 1) / 32;

    for (int i = 0; i < numFields; i++) {
      // ANOTHER COLUMN
      DBFField fieldToAdd = new DBFField();
      mapTable.addField(fieldToAdd);

      // FIELD NAME
      String fieldName = "";
      for (int j = 0; j < 11; j++) {
        byte c = dis.readByte();
        if (c != 0) fieldName += (char) c;
      }
      fieldToAdd.setName(fieldName);

      // FIELD TYPE
      byte fieldTypeAsByte = dis.readByte();
      char fieldType = (char) fieldTypeAsByte;
      if (fieldType == 'C') fieldToAdd.setType(DBFFieldType.C);
      else fieldToAdd.setType(DBFFieldType.N);

      // DISPLACEMENT OF FIELD IN RECORD (12-15)
      int displacementOfFieldInRecord = readLittleEndianInt(dis);
      fieldToAdd.setDisplacement(displacementOfFieldInRecord);

      // LENGTH OF FIELD (16)
      int lengthOfField = dis.readByte();
      if (lengthOfField < 0) lengthOfField += 256;
      fieldToAdd.setLength(lengthOfField);

      // NUMBER OF DECIMAL PLACES (17)
      byte numberOfDecimalPlaces = dis.readByte();
      fieldToAdd.setNumberOfDecimalPlaces(numberOfDecimalPlaces);

      // FIELD FLAGS (18)
      byte fieldFlags = dis.readByte();
      fieldToAdd.setFlags(fieldFlags);

      // AUTOINCREMENT NEXT (19-22)
      int next = readLittleEndianInt(dis);
      fieldToAdd.setNext(next);

      // AUTOINCREMENT STEP (23)
      byte step = dis.readByte();
      fieldToAdd.setStep(step);

      // RESERVED (24-31) - WE WON'T USE THIS
      long reservedFieldData = dis.readLong();
      fieldToAdd.setReservedData(reservedFieldData);
    }
  }