Ejemplo n.º 1
0
  /**
   * This method saves all of the fields in the mapTable argument via the dos stream, which is setup
   * at the proper location.
   *
   * @param dos Output stream writing to the .dbf file.
   * @param mapTable The dbf table being saved.
   * @throws IOException Thrown when the stream fails.
   */
  private void saveFields(DataOutputStream dos, 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++) {
      // HERE'S THE FIELD WE'RE SAVING
      DBFField fieldToSave = mapTable.getField(i);

      // FIELD NAME
      String fieldName = fieldToSave.getName();
      int j = 0;
      for (; j < fieldName.length(); j++) {
        byte c = (byte) fieldName.charAt(j);
        dos.writeByte(c);
      }
      byte z = (byte) 0x00;
      while (j < 11) {
        dos.writeByte(z);
        j++;
      }

      // FIELD TYPE
      dos.writeByte((byte) (fieldToSave.getType().toString().charAt(0)));

      // DISPLACEMENT OF FIELD IN RECORD (12-15)
      dos.writeInt(Integer.reverseBytes(fieldToSave.getDisplacement()));

      // LENGTH OF FIELD (16)
      dos.writeByte((byte) fieldToSave.getLength());

      // NUMBER OF DECIMAL PLACES (17)
      dos.writeByte(fieldToSave.getNumberOfDecimalPlaces());

      // FIELD FLAGS (18)
      dos.writeByte(fieldToSave.getFlags());

      // AUTOINCREMENT NEXT (19-22)
      dos.writeInt(Integer.reverseBytes(fieldToSave.getNext()));

      // AUTOINCREMENT STEP (23)
      dos.writeByte(fieldToSave.getStep());

      // RESERVED (24-31) - WE WON'T USE THIS
      dos.writeLong(fieldToSave.getReservedData());
    }
  }