public DBFReader(Stream anIn) { try { _dataInputStream = new BinaryReader(anIn); isClosed = false; _header = new DBFHeader(); _header.Read(_dataInputStream); /* it might be required to leap to the start of records at times */ int t_dataStartIndex = _header.HeaderLength - (32 + (32 * _header.FieldArray.Length)) - 1; if (t_dataStartIndex > 0) { _dataInputStream.ReadBytes((t_dataStartIndex)); } } catch (IOException e) { throw new DBFException("Failed To Read DBF", e); } }
public DBFWriter(Stream dbfFile) { raf = dbfFile; /* before proceeding check whether the passed in File object is an empty/non-existent file or not. */ if (raf.Length == 0) { header = new DBFHeader(); return; } header = new DBFHeader(); header.Read(new BinaryReader(raf)); /* position file pointer at the end of the raf */ raf.Seek(-1, SeekOrigin.End); /* to ignore the END_OF_DATA byte at EoF */ recordCount = header.NumberOfRecords; }
public DBFReader(string anIn) { try { _dataInputStream = new BinaryReader( File.Open(anIn, FileMode.Open, FileAccess.Read, FileShare.Read) ); var dbtPath = Path.ChangeExtension(anIn, "dbt"); if (File.Exists(dbtPath)) { _dataMemoLoc = dbtPath; } isClosed = false; _header = new DBFHeader(); _header.Read(_dataInputStream); /* it might be required to leap to the start of records at times */ int t_dataStartIndex = _header.HeaderLength - (32 + (32 * _header.FieldArray.Length)) - 1; if (t_dataStartIndex > 0) { _dataInputStream.ReadBytes((t_dataStartIndex)); } } catch (IOException ex) { throw new DBFException("Failed To Read DBF", ex); } }
/// Creates a DBFWriter which can append to records to an existing DBF file. /// @param dbfFile. The file passed in shouls be a valid DBF file. /// @exception Throws DBFException if the passed in file does exist but not a valid DBF file, or if an IO error occurs. public DBFWriter(String dbfFile) { try { raf = File.Open(dbfFile, FileMode.OpenOrCreate, FileAccess.ReadWrite); _dataMemoLoc = Path.ChangeExtension(dbfFile, "dbt"); /* before proceeding check whether the passed in File object is an empty/non-existent file or not. */ if (raf.Length == 0) { header = new DBFHeader(); return; } header = new DBFHeader(); header.Read(new BinaryReader(raf)); /* position file pointer at the end of the raf */ raf.Seek(-1, SeekOrigin.End); /* to ignore the END_OF_DATA byte at EoF */ } catch (FileNotFoundException e) { throw new DBFException("Specified file is not found. ", e); } catch (IOException e) { throw new DBFException(" while reading header", e); } recordCount = header.NumberOfRecords; }