private void writeHeader() throws IOException {
        byte FileLangId = dbfConfig.getLanguageID();
        int HeaderSize = 0;
        int RecordHeaderSize = 0;
        byte[] header = null;
        if (dbfConfig.getDbfVersion() == ru.nyrk.util.jdbf.DBFConfig.DbfVersion.xBaseVII) {
            HeaderSize = 68;
            RecordHeaderSize = 48;
            header = new byte[HeaderSize];
            header[VerDBFindex] = 0x03;
            header[4] = 0x01;
            
        } else {
            HeaderSize = 32;
            RecordHeaderSize = 32;
            header = new byte[HeaderSize];
            if (dbfConfig.getDbfVersion() == ru.nyrk.util.jdbf.DBFConfig.DbfVersion.xFoxPro)
            {   
                header[VerDBFindex] = 0x03;
                header[FileLangIdindex] = (byte)0xc9;
                HeaderSize += 263; 
            }    
            else
                header[VerDBFindex] = 0x03;
            // standard language WE, dBase III no language support
            if (dbfConfig.getDbfVersion() == ru.nyrk.util.jdbf.DBFConfig.DbfVersion.xBaseIII)
                header[FileLangIdindex] = 0;
        }

        Calendar clnd = Calendar.getInstance();
        header[1] = (byte)(clnd.get(1) - 2000);
        header[2] = (byte)(clnd.get(2)+1);
        header[3] = (byte)clnd.get(5);
        if(dbfConfig.getRecCount() > 0){
           copyTo(header, intToByteArray(dbfConfig.getRecCount()), 4 );
        }
         
        int fieldsize = HeaderSize + RecordHeaderSize* fields.length+1;
        header[8] = (byte)(fieldsize % 256);
        header[9] = (byte)(fieldsize / 256);

        int recsize = 1;

        for (int i = 0; i < fields.length; i++)
            recsize += fields[i].getLength();
        header[10] = (byte)(recsize % 256);
        header[11] = (byte)(recsize / 256);
        
        stream.write(header, 0, header.length);
        
    }