コード例 #1
0
ファイル: DBFFileIO.java プロジェクト: ameltzer/mapapplet
  /**
   * This helper method saves just the .dbf file header portion of the mapTable argument using the
   * dos stream.
   *
   * @param dos The stream writing to the .dbf file.
   * @param mapTable The dbf table being saved.
   * @throws IOException Thrown when the stream fails.
   */
  private void saveHeader(DataOutputStream dos, DBFTable mapTable) throws IOException {
    // DBF file type (0)
    dos.writeByte(mapTable.getFileType());

    // LAST UPDATE (1-3)
    byte year = (byte) (mapTable.getLastModifiedDate().get(Calendar.YEAR) - 1900);
    byte month = (byte) (mapTable.getLastModifiedDate().get(Calendar.MONTH) + 1);
    byte day = (byte) (mapTable.getLastModifiedDate().get(Calendar.DATE));
    dos.writeByte(year);
    dos.writeByte(month);
    dos.writeByte(day);

    // NUMBER OF RECORDS IN FILE (4-7)
    int numberOfRecordsInFile = Integer.reverseBytes(mapTable.getNumberOfRecords());
    dos.writeInt(numberOfRecordsInFile);

    // POSITION OF FIRST DATA RECORDED (8-9)
    short positionOfFirstDataRecorded =
        Short.reverseBytes(mapTable.getPositionOfFirstDataRecorded());
    dos.writeShort(positionOfFirstDataRecorded);

    // LENGTH OF ONE DATA RECORD, INCLUDING DELETE FLAG (10-11)
    short dataRecordLength = Short.reverseBytes(mapTable.getDataRecordLength());
    dos.writeShort(dataRecordLength);

    // ZEROES (12-13)
    short zeroes = Short.reverseBytes(mapTable.getZeroes());
    dos.writeShort(zeroes);

    // DBASE IV Transaction Flag (14)
    dos.writeByte(mapTable.getDbaseTransactionFlag());

    // DBASE IV Encryption Flag (15)
    dos.writeByte(mapTable.getDbaseEncryptionFlag());

    // Multiuser Processing 12 Bytes (16-27)
    int[] mup = mapTable.getMup();
    dos.writeInt(Integer.reverseBytes(mup[0]));
    dos.writeInt(Integer.reverseBytes(mup[1]));
    dos.writeInt(Integer.reverseBytes(mup[2]));

    // TABLE FLAGS (28)
    dos.writeByte(mapTable.getFlags());

    // CODE PAGE MARK/LANGUAGE DRIVER ID (29)
    dos.writeByte(mapTable.getCodePageMark());

    // RESERVED, CONTAINS 0x00 (30-31)
    dos.writeShort(Short.reverseBytes(mapTable.getReserved()));
  }