Ejemplo n.º 1
0
        /// <summary>
        /// Open a DBF from a FileStream. This can be a file or an internet connection stream. Make sure that it is positioned at start of DBF file.
        /// Reading a DBF over the internet we can not determine size of the file, so we support HasMore(), ReadNext() interface.
        /// RecordCount information in header can not be trusted always, since some packages store 0 there.
        /// </summary>
        /// <param name="ofs"></param>
        public void Open(Stream ofs)
        {
            if (_dbfFile != null)
            {
                Close();
            }

            _dbfFile       = ofs;
            _dbfFileReader = null;
            _dbfFileWriter = null;

            if (_dbfFile.CanRead)
            {
                _dbfFileReader = new BinaryReader(_dbfFile, encoding);
            }

            if (_dbfFile.CanWrite)
            {
                _dbfFileWriter = new BinaryWriter(_dbfFile, encoding);
            }

            //reset position
            _recordsReadCount = 0;

            //assume header is not written
            _headerWritten = false;

            //read the header
            if (ofs.CanRead)
            {
                //try to read the header...
                try
                {
                    _header.Read(_dbfFileReader);
                    _headerWritten = true;
                }
                catch (EndOfStreamException)
                {
                    //could not read header, file is empty
                    _header        = new DbfHeader(encoding);
                    _headerWritten = false;
                }
            }

            if (_dbfFile != null)
            {
                _isReadOnly    = !_dbfFile.CanWrite;
                _isForwardOnly = !_dbfFile.CanSeek;
            }
        }
        /// <summary>
        /// Open a DBF from a FileStream. This can be a file or an internet connection stream. Make sure that it is positioned at start of DBF file.
        /// Reading a DBF over the internet we can not determine size of the file, so we support HasMore(), ReadNext() interface.
        /// RecordCount information in header can not be trusted always, since some packages store 0 there.
        /// </summary>
        /// <param name="ofs"></param>
        public void Open(Stream ofs)
        {
            if (mDbfFile != null)
            {
                Close();
            }

            mDbfFile       = ofs;
            mDbfFileReader = null;
            mDbfFileWriter = null;

            if (mDbfFile.CanRead)
            {
                mDbfFileReader = new BinaryReader(mDbfFile, Encoding.ASCII);
            }

            if (mDbfFile.CanWrite)
            {
                mDbfFileWriter = new BinaryWriter(mDbfFile, Encoding.ASCII);
            }

            //reset position
            mRecordsReadCount = 0;

            //assume header is not written
            mHeaderWritten = false;

            //read the header
            if (ofs.CanRead)
            {
                //try to read the header...
                try
                {
                    mHeader.Read(mDbfFileReader);
                    mHeaderWritten = true;
                }
                catch (EndOfStreamException)
                {
                    //could not read header, file is empty
                    mHeader        = new DbfHeader();
                    mHeaderWritten = false;
                }
            }

            if (mDbfFile != null)
            {
                mIsReadOnly    = !mDbfFile.CanWrite;
                mIsForwardOnly = !mDbfFile.CanSeek;
            }
        }