Example #1
0
        private void WriteHeader(Stream stream, bool withColumns)
        {
            mDbfHeader.NbRecords = (UInt32)mRecordCount;

            UInt16 newHeaderWith = (UInt16)(mDbfHeaderWriter.RecordWidth + (mColumns.Count - 1) * mDbfColumnWriter.RecordWidth + 1);

            mDbfHeader.HeaderWidth = newHeaderWith;
            mHeaderWidth           = newHeaderWith;

            Byte[] headerBuff = new byte[mDbfHeaderWriter.RecordWidth];
            mDbfHeaderWriter.Write(this, headerBuff, mDbfHeader);

            stream.Seek(0, SeekOrigin.Begin);
            stream.Write(headerBuff, 0, headerBuff.Length);
#if DUMP_DISK_ACTIVITY
            System.Diagnostics.Debug.WriteLine(mOriginalFile + " WriteHeader");
            System.Diagnostics.Debug.WriteLine(Utils.HexDump(headerBuff));
#endif

            if (withColumns)
            {
                Byte[]          columnHeaderBuff = new byte[mDbfColumnWriter.RecordWidth];
                DbfColumnHeader dbfColumnHeader  = new DbfColumnHeader();
                // we ignore column 0
                for (int i = 1; i < mColumns.Count; i++)
                {
                    ColumnDefinition c = mColumns[i];
                    dbfColumnHeader.ColumnName  = c.mColumnName;
                    dbfColumnHeader.ColumnType  = c.DbfColumnType;
                    dbfColumnHeader.ColumnWidth = (byte)c.mWidth;
                    dbfColumnHeader.Decimals    = (byte)c.mDecimals;

                    mDbfColumnWriter.Write(this, columnHeaderBuff, dbfColumnHeader);
                    stream.Write(columnHeaderBuff, 0, columnHeaderBuff.Length);
#if DUMP_DISK_ACTIVITY
                    System.Diagnostics.Debug.WriteLine(mOriginalFile + " WriteColumn #" + i);
                    System.Diagnostics.Debug.WriteLine(Utils.HexDump(columnHeaderBuff));
#endif
                }
                stream.WriteByte(END_OF_COLUMN_DEFINITIONS);
            }
            base.mCurrentRecordNoPosition = UInt32.MaxValue;
        }
Example #2
0
 internal override bool OnFillWriteBuffer(Record record, Byte[] buffer)
 {
     mRecordWriter.Write(this, buffer, (TRecord)record);
     return(true);
 }