6/28/2007
13 |
14 | */
15 | /**
16 | Base class for DBFReader and DBFWriter.
17 | */
18 |
19 | using System;
20 | using System.Text;
21 |
22 | namespace DotNetDBF
23 | {
24 | public abstract class DBFBase
25 | {
26 |
27 | public Encoding CharEncoding { get; set; } = Encoding.GetEncoding("utf-8");
28 |
29 | public int BlockSize { get; set; } = 512;
30 |
31 | private string _nullSymbol;
32 | public string NullSymbol
33 | {
34 | get => _nullSymbol ?? DBFFieldType.Unknown;
35 | set
36 | {
37 | if (value != null && value.Length != 1)
38 | throw new ArgumentException(nameof(NullSymbol));
39 | _nullSymbol = value;
40 | }
41 | }
42 |
43 | }
44 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | dotnetdbf
2 | =========
3 |
4 | This is a basic file parser written in C# for reading and writing xBase DBF files.
5 | Pure .NET direct access to xBase DBF. No need OBBC/JDBC for readind and writeing xBase DBF.
6 | xBase DBF files are used by Clipper and FoxPro.
7 |
8 | Compilable on Linux (Mono).
9 | For .net 4.0 projects there is an enumeration framework in which makes it easy to use Linq to Objects.
10 |
11 | Code derived from javadbf.
12 |
13 | ## Get The Binaries
14 | Use [NuGet](http://nuget.org/packages/dotnetdbf/) from Visual Studio
15 |
16 | ## Quick start
17 | Writng ODF
18 |
19 |
20 | using (Stream fos = File.Open(dbffile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
21 | using (var writer = new DBFWriter())
22 | {
23 | writer.CharEncoding = Encoding.GetEncoding(866);
24 | writer.Signature = DBFSigniture.DBase3;
25 | writer.LanguageDriver = 0x26; // Eq to CP866
26 | var field1 = new DBFField("DOCDATE", NativeDbType.Date);
27 | var field2 = new DBFField("DOCNUMBER", NativeDbType.Char, 50);
28 | ...
29 | var field9 = new DBFField("f9", NativeDbType.Char, 20);
30 | writer.Fields = new[] { field1, field2, field3, field4, field5, field6, field7, field8, field9 };
31 | foreach (var item in items)
32 | {
33 | writer.AddRecord(
34 | ...
35 | );
36 | }
37 | writer.Write(fos);
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/DotNetDBF/DBFException.cs:
--------------------------------------------------------------------------------
1 | /*
2 | DBFException
3 | Represents exceptions happen in the JAvaDBF classes.
4 |
5 | This file is part of DotNetDBF packege.
6 |
7 | original author (javadbf): anil@linuxense.com 2004/03/31
8 | license: LGPL (http://www.gnu.org/copyleft/lesser.html)
9 |
10 | ported to C# (DotNetDBF): Jay Tuley 6/28/2007
11 |
12 | */
13 |
14 | using System;
15 | using System.IO;
16 |
17 | namespace DotNetDBF
18 | {
19 | public class DBTException : DBFException
20 | {
21 |
22 | public DBTException(string msg) : base(msg)
23 | {
24 | }
25 |
26 | public DBTException(string msg, Exception internalException)
27 | : base(msg, internalException)
28 | {
29 | }
30 | }
31 |
32 | public class DBFRecordException : DBFException
33 | {
34 | public int Record { get; }
35 |
36 | public DBFRecordException(string msg, int record) : base(msg)
37 | {
38 | Record = record;
39 | }
40 |
41 | public DBFRecordException(string msg, Exception internalException)
42 | : base(msg, internalException)
43 | {
44 | }
45 | }
46 |
47 | public class DBFException : IOException
48 | {
49 | public DBFException() : base()
50 | {
51 | }
52 |
53 | public DBFException(string msg) : base(msg)
54 | {
55 | }
56 |
57 | public DBFException(string msg, Exception internalException)
58 | : base(msg, internalException)
59 | {
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/DotNetDBF.Test/dbfs/foxprodb/calls.FPT:
--------------------------------------------------------------------------------
1 | @ LNancy told me about their blends. Thinking about it. Should call back later. Usual monthly order. +Asked Nancy about their Hazelnut flavoring. 'Placed a special order on the Hazelnut. Changed the usual monthly order. GSpoke to Janet about NWIND carrying a coffee collection designed by us. 5Too high - should wait and see if Janet comes around. ;She offered $100 less per order (12 packages / order) - OK. Set up marketing plans w/ Janet. Confirmation of shipment. Got Some really odd new blends. Even more new blends. Ordered a sample. Ordered 1000 lbs. - good stuff. $Shipment to Margaret was late, oops. )Margaret's shipment went to Steven, oops.
--------------------------------------------------------------------------------
/DotNetDBF/DotNetDBF.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net472;netstandard2.0
4 | True
5 | sn.snk
6 | Ekon Benefits
7 | Copyright 2009-2017
8 | This is a basic file parser for reading and writing xBase DBF files particularlly Clipper. Code originally derived from javadbf.
9 | https://github.com/ekonbenefits/dotnetdbf
10 | clipper xbase dbf
11 | Anil Kumar, Jay Tuley
12 | True
13 | True
14 | https://github.com/ekonbenefits/dotnetdbf
15 | git
16 | True
17 | True
18 | LGPL-2.1-or-later
19 | snupkg
20 | true
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/DotNetDBF.Enumerable/DotNetDBF.Enumerable.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net472;netstandard2.0
4 | True
5 | sn.snk
6 | dotnetdbf.enumerable
7 | Jay Tuley
8 | Ekon Benefits
9 | For dotnetdbf projects using .net 4.0 projects this is an enumeration framework in which makes it easy to use Linq to Objects.
10 | lgpl
11 | https://github.com/ekonbenefits/dotnetdbf
12 | clipper xbase dbf linq
13 | LGPL-2.1-or-later
14 | https://github.com/ekonbenefits/dotnetdbf
15 | https://github.com/ekonbenefits/dotnetdbf
16 | gits
17 | True
18 | True
19 | snupkg
20 | true
21 | True
22 | True
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/DotNetDBF.Test/dbfs/dbase_03_summary.txt:
--------------------------------------------------------------------------------
1 |
2 | Database: dbase_03.dbf
3 | Type: (03) dBase III without memo file
4 | Memo File: false
5 | Records: 14
6 |
7 | Fields:
8 | Name Type Length Decimal
9 | ------------------------------------------------------------------------------
10 | Point_ID C 12 0
11 | Type C 20 0
12 | Shape C 20 0
13 | Circular_D C 20 0
14 | Non_circul C 60 0
15 | Flow_prese C 20 0
16 | Condition C 20 0
17 | Comments C 60 0
18 | Date_Visit D 8 0
19 | Time C 10 0
20 | Max_PDOP N 5 1
21 | Max_HDOP N 5 1
22 | Corr_Type C 36 0
23 | Rcvr_Type C 36 0
24 | GPS_Date D 8 0
25 | GPS_Time C 10 0
26 | Update_Sta C 36 0
27 | Feat_Name C 20 0
28 | Datafile C 20 0
29 | Unfilt_Pos N 10 0
30 | Filt_Pos N 10 0
31 | Data_Dicti C 20 0
32 | GPS_Week N 6 0
33 | GPS_Second N 12 3
34 | GPS_Height N 16 3
35 | Vert_Prec N 16 1
36 | Horz_Prec N 16 1
37 | Std_Dev N 16 6
38 | Northing N 16 3
39 | Easting N 16 3
40 | Point_ID N 9 0
41 |
--------------------------------------------------------------------------------
/DotNetDBF.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 15
3 | VisualStudioVersion = 15.0.26228.9
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetDBF", "DotNetDBF\DotNetDBF.csproj", "{C5E9AE18-1EA3-4C90-AFAB-5323093BE4AC}"
6 | EndProject
7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetDBF.Enumerable", "DotNetDBF.Enumerable\DotNetDBF.Enumerable.csproj", "{3BB97ECD-325D-4288-B355-57CFC1404019}"
8 | EndProject
9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetDBF.Test", "DotNetDBF.Test\DotNetDBF.Test.csproj", "{8D5436E3-F584-40A0-ACDC-65346ECEADB0}"
10 | EndProject
11 | Global
12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
13 | Debug|Any CPU = Debug|Any CPU
14 | Release|Any CPU = Release|Any CPU
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {C5E9AE18-1EA3-4C90-AFAB-5323093BE4AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {C5E9AE18-1EA3-4C90-AFAB-5323093BE4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {C5E9AE18-1EA3-4C90-AFAB-5323093BE4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {C5E9AE18-1EA3-4C90-AFAB-5323093BE4AC}.Release|Any CPU.Build.0 = Release|Any CPU
21 | {3BB97ECD-325D-4288-B355-57CFC1404019}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {3BB97ECD-325D-4288-B355-57CFC1404019}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {3BB97ECD-325D-4288-B355-57CFC1404019}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {3BB97ECD-325D-4288-B355-57CFC1404019}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {8D5436E3-F584-40A0-ACDC-65346ECEADB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {8D5436E3-F584-40A0-ACDC-65346ECEADB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {8D5436E3-F584-40A0-ACDC-65346ECEADB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {8D5436E3-F584-40A0-ACDC-65346ECEADB0}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(SolutionProperties) = preSolution
31 | HideSolutionNode = FALSE
32 | EndGlobalSection
33 | EndGlobal
34 |
--------------------------------------------------------------------------------
/DotNetDBF.Test/DotNetDBF.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net8.0;net472
4 | Exe
5 | Copyright © 2017
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/DotNetDBF/DBFFieldType.cs:
--------------------------------------------------------------------------------
1 | /*
2 | DBFFieldType
3 | Class for reading the records assuming that the given
4 | InputStream comtains DBF data.
5 |
6 | This file is part of DotNetDBF packege.
7 |
8 | author (DotNetDBF): Jay Tuley 6/28/2007
9 |
10 | License: LGPL (http://www.gnu.org/copyleft/lesser.html)
11 |
12 | */
13 |
14 | using System.Data;
15 |
16 |
17 | namespace DotNetDBF
18 | {
19 | public enum NativeDbType : byte
20 | {
21 | Autoincrement = (byte) 0x2B, //+ in ASCII
22 | Timestamp = (byte) 0x40, //@ in ASCII
23 | Binary = (byte) 0x42, //B in ASCII
24 | Char = (byte) 0x43, //C in ASCII
25 | Date = (byte) 0x44, //D in ASCII
26 | Float = (byte) 0x46, //F in ASCII
27 | Ole = (byte) 0x47, //G in ASCII
28 | Long = (byte) 0x49, //I in ASCII
29 | Logical = (byte) 0x4C, //L in ASCII
30 | Memo = (byte) 0x4D, //M in ASCII
31 | Numeric = (byte) 0x4E, //N in ASCII
32 | Double = (byte) 0x4F, //O in ASCII
33 | }
34 |
35 | public static class DBFFieldType
36 | {
37 | public const byte EndOfData = 0x1A; //^Z End of File
38 | public const byte EndOfField = 0x0D; //End of Field
39 | public const byte False = 0x46; //F in Ascii
40 | public const byte Space = 0x20; //Space in ascii
41 | public const byte True = 0x54; //T in ascii
42 | public const byte UnknownByte = 0x3F; //Unknown Bool value
43 | public const string Unknown = "?"; //Unknown value
44 |
45 | public static DbType FromNative(NativeDbType @byte)
46 | {
47 | switch (@byte)
48 | {
49 | case NativeDbType.Char:
50 | return DbType.AnsiStringFixedLength;
51 | case NativeDbType.Logical:
52 | return DbType.Boolean;
53 | case NativeDbType.Numeric:
54 | return DbType.Decimal;
55 | case NativeDbType.Date:
56 | return DbType.Date;
57 | case NativeDbType.Float:
58 | return DbType.Decimal;
59 | case NativeDbType.Memo:
60 | return DbType.AnsiString;
61 | default:
62 | return DbType.Object;
63 | }
64 | }
65 |
66 | public static NativeDbType FromDbType(DbType dbType)
67 | {
68 | switch (dbType)
69 | {
70 | case DbType.AnsiStringFixedLength:
71 | return NativeDbType.Char;
72 | case DbType.Boolean:
73 | return NativeDbType.Logical;
74 | case DbType.Decimal:
75 | return NativeDbType.Numeric;
76 | case DbType.Date:
77 | return NativeDbType.Date;
78 | case DbType.AnsiString:
79 | return NativeDbType.Memo;
80 | default:
81 | throw new DBFException(
82 | $"Unsupported Type {dbType}");
83 | }
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/DotNetDBF.Test/dbfs/dbase_f5_summary.txt:
--------------------------------------------------------------------------------
1 |
2 | Database: dbase_f5.dbf
3 | Type: (f5) FoxPro with memo file
4 | Memo File: true
5 | Records: 975
6 |
7 | Fields:
8 | Name Type Length Decimal
9 | ------------------------------------------------------------------------------
10 | NF N 5 0
11 | SEXE C 1 0
12 | NOM C 20 0
13 | COG1 C 15 0
14 | COG2 C 15 0
15 | TELEFON C 9 0
16 | RENOM C 15 0
17 | NFP N 5 0
18 | NFM N 5 0
19 | ARXN C 10 0
20 | DATN D 8 0
21 | LLON C 15 0
22 | MUNN C 15 0
23 | COMN C 15 0
24 | PROV C 15 0
25 | PAIN C 15 0
26 | OFIC C 15 0
27 | ARXB C 10 0
28 | DATB D 8 0
29 | LLOB C 15 0
30 | MUNB C 15 0
31 | COMB C 15 0
32 | PAIB C 15 0
33 | DRIB C 30 0
34 | INAB C 30 0
35 | OFTB C 10 0
36 | OFNB C 20 0
37 | AXC1 C 10 0
38 | DTC1 D 8 0
39 | LLC1 C 15 0
40 | NFC1 N 5 0
41 | TCA1 C 10 0
42 | OTC1 C 10 0
43 | ONC1 C 20 0
44 | AXC2 C 10 0
45 | DTC2 D 8 0
46 | LLC2 C 15 0
47 | NFC2 N 5 0
48 | TCA2 C 10 0
49 | OTC2 C 10 0
50 | ONC2 C 20 0
51 | AXC3 C 10 0
52 | DTC3 D 8 0
53 | LLC3 C 15 0
54 | NFC3 N 5 0
55 | TCA3 C 10 0
56 | OTC3 C 10 0
57 | ONC3 C 20 0
58 | ARXD C 10 0
59 | DATD D 8 0
60 | LLOD C 15 0
61 | OFTD C 10 0
62 | OFND C 20 0
63 | OBS1 C 70 0
64 | OBS2 C 70 0
65 | OBS3 C 70 0
66 | OBS4 C 70 0
67 | OBSE M 10 0
68 | GHD C 15 0
69 |
--------------------------------------------------------------------------------
/DotNetDBF/original java src/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | Utils
3 | Class for contining utility functions.
4 |
5 | This file is part of JavaDBF packege.
6 |
7 | author: anil@linuxense.com
8 | license: LGPL (http://www.gnu.org/copyleft/lesser.html)
9 |
10 | $Id: Utils.java,v 1.7 2004/03/31 16:00:34 anil Exp $
11 | */
12 | package com.linuxense.javadbf;
13 |
14 | import java.io.*;
15 | import java.util.*;
16 | import java.text.*;
17 |
18 | /**
19 | Miscelaneous functions required by the JavaDBF package.
20 | */
21 | public final class Utils {
22 |
23 | public static final int ALIGN_LEFT = 10;
24 | public static final int ALIGN_RIGHT = 12;
25 |
26 | private Utils(){}
27 |
28 | public static int readLittleEndianInt( DataInput in)
29 | throws IOException {
30 |
31 | int bigEndian = 0;
32 | for( int shiftBy=0; shiftBy<32; shiftBy+=8) {
33 |
34 | bigEndian |= (in.readUnsignedByte()&0xff) << shiftBy;
35 | }
36 |
37 | return bigEndian;
38 | }
39 |
40 | public static short readLittleEndianShort( DataInput in)
41 | throws IOException {
42 |
43 | int low = in.readUnsignedByte() & 0xff;
44 | int high = in.readUnsignedByte();
45 |
46 | return (short )(high << 8 | low);
47 | }
48 |
49 | public static byte[] trimLeftSpaces( byte [] arr) {
50 |
51 | StringBuffer t_sb = new StringBuffer( arr.length);
52 |
53 | for( int i=0; i>8;
74 |
75 | return num2;
76 | }
77 |
78 | public static int littleEndian(int value) {
79 |
80 | int num1 = value;
81 | int mask = 0xff;
82 | int num2 = 0x00;
83 |
84 | num2 |= num1 & mask;
85 |
86 | for( int i=1; i<4; i++) {
87 |
88 | num2<<=8;
89 | mask <<= 8;
90 | num2 |= (num1 & mask)>>(8*i);
91 | }
92 |
93 | return num2;
94 | }
95 |
96 | public static byte[] textPadding( String text, String characterSetName, int length) throws java.io.UnsupportedEncodingException {
97 |
98 | return textPadding( text, characterSetName, length, Utils.ALIGN_LEFT);
99 | }
100 |
101 | public static byte[] textPadding( String text, String characterSetName, int length, int alignment) throws java.io.UnsupportedEncodingException {
102 |
103 | return textPadding( text, characterSetName, length, alignment, (byte)' ');
104 | }
105 |
106 | public static byte[] textPadding( String text, String characterSetName, int length, int alignment,
107 | byte paddingByte) throws java.io.UnsupportedEncodingException {
108 |
109 | if( text.length() >= length) {
110 |
111 | return text.substring( 0, length).getBytes( characterSetName);
112 | }
113 |
114 | byte byte_array[] = new byte[ length];
115 | Arrays.fill( byte_array, paddingByte);
116 |
117 | switch( alignment) {
118 |
119 | case ALIGN_LEFT:
120 | System.arraycopy( text.getBytes( characterSetName), 0, byte_array, 0, text.length());
121 | break;
122 |
123 | case ALIGN_RIGHT:
124 | int t_offset = length - text.length();
125 | System.arraycopy( text.getBytes( characterSetName), 0, byte_array, t_offset, text.length());
126 | break;
127 | }
128 |
129 | return byte_array;
130 | }
131 |
132 | public static byte[] doubleFormating( Double doubleNum, String characterSetName, int fieldLength, int sizeDecimalPart) throws java.io.UnsupportedEncodingException{
133 |
134 | int sizeWholePart = fieldLength - (sizeDecimalPart>0?( sizeDecimalPart + 1):0);
135 |
136 | StringBuffer format = new StringBuffer( fieldLength);
137 |
138 | for( int i=0; i 0) {
144 |
145 | format.append( ".");
146 |
147 | for( int i=0; i
10 | /// Interface to get the contents of the DBF Wrapper
11 | ///
12 | ///
13 | [Obsolete("DotNetDBF.Enumerable.IDBFInterceptor is the new interface name",error:true)]
14 | public interface IDBFIntercepter:IDBFInterceptor
15 | {
16 |
17 | }
18 |
19 |
20 | [Obsolete("DotNetDBF.Enumerable.DBFInterceptor is the new class name")]
21 | public class DBFIntercepter : DBFEnumerable.DBFIntercepter
22 | {
23 | public DBFIntercepter(object[] wrappedObj, string[] fieldNames) : base(wrappedObj, fieldNames)
24 | {
25 | }
26 | }
27 |
28 |
29 | }
30 |
31 |
32 | namespace DotNetDBF.Enumerable
33 | {
34 | public static partial class DBFEnumerable
35 | {
36 | [Obsolete("DotNetDBF.Enumerable.IDBFIntercepter is the new interface name")]
37 | public interface IDBFIntercepter : DotNetDBF.Enumerable.IDBFIntercepter
38 | {
39 | }
40 |
41 | [Obsolete("DotNetDBF.Enumerable.DBFIntercepter is the new class name")]
42 | public class DBFIntercepter : DotNetDBF.Enumerable.Enuemrable.DBFIntercepter, IDBFIntercepter
43 | {
44 | public DBFIntercepter(object[] wrappedObj, string[] fieldNames)
45 | : base(wrappedObj, fieldNames)
46 | {
47 | }
48 | }
49 | }
50 |
51 |
52 | [Obsolete("DBFEnumerable is the new class name")]
53 | public static class Enuemrable
54 | {
55 | ///
56 | /// New Blank Row Dynamic object that matches writer;
57 | ///
58 | /// The writer.
59 | ///
60 | public static dynamic NewBlankRow(DBFWriter writer)
61 | {
62 | return writer.NewBlankRow();
63 | }
64 |
65 |
66 | ///
67 | /// Writes the record.
68 | ///
69 | /// The writer.
70 | /// The value.
71 | public static void WriteRecord(DBFWriter writer, IDBFIntercepter value)
72 | {
73 | writer.WriteRecord(value);
74 | }
75 |
76 | ///
77 | /// Adds the record.
78 | ///
79 | /// The writer.
80 | /// The value.
81 | public static void AddRecord(DBFWriter writer, IDBFIntercepter value)
82 | {
83 | writer.AddRecord(writer, value);
84 | }
85 |
86 | ///
87 | /// Return all the records. T should be interface with getter properties that match types and names of the database.
88 | /// Optionally instead of T being and interface you can pass in an anonymous object with properties that match that
89 | /// database and then you'll get an IEnumerable of that anonymous type with the data filled in.
90 | ///
91 | ///
92 | /// The reader.
93 | /// The prototype. Anonymous class instance
94 | ///
95 | public static IEnumerable AllRecords(DBFReader reader, T prototype = null) where T : class
96 | {
97 | return reader.AllRecords(prototype);
98 | }
99 |
100 | ///
101 | /// Returns a list of dynamic objects whose properties and types match up with that database name.
102 | ///
103 | /// The reader.
104 | /// The where column name.
105 | /// What the were column should equal.
106 | ///
107 | public static IEnumerable DynamicAllRecords(DBFReader reader, string whereColumn = null,
108 | dynamic whereColumnEquals = null)
109 | {
110 | return reader.DynamicAllRecords(whereColumn, (object) whereColumnEquals);
111 | }
112 |
113 |
114 | [Obsolete("DotNetDBF.Enumerable.IDBFIntercepter is the new interface name",error:true)]
115 | public interface IDBFIntercepter : DotNetDBF.Enumerable.IDBFInterceptor
116 | {
117 | }
118 |
119 | [Obsolete("DotNetDBF.Enumerable.DBFIntercepter is the new class name")]
120 | public class DBFIntercepter : DotNetDBF.Enumerable.BaseDBFInterceptor, IDBFIntercepter
121 | {
122 | public DBFIntercepter(object[] wrappedObj, string[] fieldNames)
123 | : base(wrappedObj, fieldNames)
124 | {
125 | }
126 | }
127 | }
128 | }
--------------------------------------------------------------------------------
/DotNetDBF/original java src/DBFHeader.java:
--------------------------------------------------------------------------------
1 | /*
2 | DBFHeader
3 | Class for reading the metadata assuming that the given
4 | InputStream carries DBF data.
5 |
6 | This file is part of JavaDBF packege.
7 |
8 | Author: anil@linuxense.com
9 | License: LGPL (http://www.gnu.org/copyleft/lesser.html)
10 |
11 | $Id$
12 | */
13 |
14 | package com.linuxense.javadbf;
15 |
16 | import java.io.*;
17 | import java.util.*;
18 |
19 | class DBFHeader {
20 |
21 | static final byte SIG_DBASE_III = (byte)0x03;
22 | /* DBF structure start here */
23 |
24 | byte signature; /* 0 */
25 | byte year; /* 1 */
26 | byte month; /* 2 */
27 | byte day; /* 3 */
28 | int numberOfRecords; /* 4-7 */
29 | short headerLength; /* 8-9 */
30 | short recordLength; /* 10-11 */
31 | short reserv1; /* 12-13 */
32 | byte incompleteTransaction; /* 14 */
33 | byte encryptionFlag; /* 15 */
34 | int freeRecordThread; /* 16-19 */
35 | int reserv2; /* 20-23 */
36 | int reserv3; /* 24-27 */
37 | byte mdxFlag; /* 28 */
38 | byte languageDriver; /* 29 */
39 | short reserv4; /* 30-31 */
40 | DBFField []fieldArray; /* each 32 bytes */
41 | byte terminator1; /* n+1 */
42 |
43 | //byte[] databaseContainer; /* 263 bytes */
44 | /* DBF structure ends here */
45 |
46 | DBFHeader() {
47 |
48 | this.signature = SIG_DBASE_III;
49 | this.terminator1 = 0x0D;
50 | }
51 |
52 | void read( DataInput dataInput) throws IOException {
53 |
54 | signature = dataInput.readByte(); /* 0 */
55 | year = dataInput.readByte(); /* 1 */
56 | month = dataInput.readByte(); /* 2 */
57 | day = dataInput.readByte(); /* 3 */
58 | numberOfRecords = Utils.readLittleEndianInt( dataInput); /* 4-7 */
59 |
60 | headerLength = Utils.readLittleEndianShort( dataInput); /* 8-9 */
61 | recordLength = Utils.readLittleEndianShort( dataInput); /* 10-11 */
62 |
63 | reserv1 = Utils.readLittleEndianShort( dataInput); /* 12-13 */
64 | incompleteTransaction = dataInput.readByte(); /* 14 */
65 | encryptionFlag = dataInput.readByte(); /* 15 */
66 | freeRecordThread = Utils.readLittleEndianInt( dataInput); /* 16-19 */
67 | reserv2 = dataInput.readInt(); /* 20-23 */
68 | reserv3 = dataInput.readInt(); /* 24-27 */
69 | mdxFlag = dataInput.readByte(); /* 28 */
70 | languageDriver = dataInput.readByte(); /* 29 */
71 | reserv4 = Utils.readLittleEndianShort( dataInput); /* 30-31 */
72 |
73 | Vector v_fields = new Vector();
74 |
75 | DBFField field = DBFField.createField( dataInput); /* 32 each */
76 | while( field != null) {
77 |
78 | v_fields.addElement( field);
79 | field = DBFField.createField( dataInput);
80 | }
81 |
82 | fieldArray = new DBFField[ v_fields.size()];
83 |
84 | for( int i=0; i 6/28/2007
12 |
13 | */
14 |
15 | using System;
16 | using System.Collections.Generic;
17 | using System.Globalization;
18 | using System.Linq;
19 | using System.Text;
20 | using System.Threading;
21 |
22 | namespace DotNetDBF
23 | {
24 | public static class Utils
25 | {
26 | public const int ALIGN_LEFT = 10;
27 | public const int ALIGN_RIGHT = 12;
28 |
29 | public static byte[] FillArray(byte[] anArray, byte value)
30 | {
31 | for (var i = 0; i < anArray.Length; i++)
32 | {
33 | anArray[i] = value;
34 | }
35 | return anArray;
36 | }
37 |
38 | public static byte[] trimLeftSpaces(byte[] arr)
39 | {
40 | var tList = new List(arr.Length);
41 |
42 | for (var i = 0; i < arr.Length; i++)
43 | {
44 | if (arr[i] != ' ')
45 | {
46 | tList.Add(arr[i]);
47 | }
48 | }
49 | return tList.ToArray();
50 | }
51 |
52 | public static byte[] textPadding(string text,
53 | Encoding charEncoding,
54 | int length)
55 | {
56 | return textPadding(text, charEncoding, length, ALIGN_LEFT);
57 | }
58 |
59 | public static byte[] textPadding(string text,
60 | Encoding charEncoding,
61 | int length,
62 | int alignment)
63 | {
64 | return
65 | textPadding(text,
66 | charEncoding,
67 | length,
68 | alignment,
69 | DBFFieldType.Space);
70 | }
71 |
72 | public static byte[] textPadding(string text,
73 | Encoding charEncoding,
74 | int length,
75 | int alignment,
76 | byte paddingByte)
77 | {
78 | var tEncoding = charEncoding;
79 | var inputBytes = tEncoding.GetBytes(text);
80 | if (inputBytes.Length >= length)
81 | {
82 | return inputBytes.Take(length).ToArray();
83 | }
84 |
85 | var byte_array = FillArray(new byte[length], paddingByte);
86 |
87 | switch (alignment)
88 | {
89 | case ALIGN_LEFT:
90 | Array.Copy(inputBytes,
91 | 0,
92 | byte_array,
93 | 0,
94 | inputBytes.Length);
95 | break;
96 |
97 | case ALIGN_RIGHT:
98 | var t_offset = length - text.Length;
99 | Array.Copy(inputBytes,
100 | 0,
101 | byte_array,
102 | t_offset,
103 | inputBytes.Length);
104 | break;
105 | }
106 |
107 | return byte_array;
108 | }
109 |
110 | public static byte[] NumericFormating(IFormattable doubleNum,
111 | Encoding charEncoding,
112 | int fieldLength,
113 | int sizeDecimalPart)
114 | {
115 | var sizeWholePart = fieldLength
116 | -
117 | (sizeDecimalPart > 0 ? (sizeDecimalPart + 1) : 0);
118 |
119 | var format = new StringBuilder(fieldLength);
120 |
121 | for (var i = 0; i < sizeWholePart; i++)
122 | {
123 | format.Append(i + 1 == sizeWholePart ? "0" : "#");
124 | }
125 |
126 | if (sizeDecimalPart > 0)
127 | {
128 | format.Append(".");
129 |
130 | for (var i = 0; i < sizeDecimalPart; i++)
131 | {
132 | format.Append("0");
133 | }
134 | }
135 |
136 |
137 | return
138 | textPadding(
139 | doubleNum.ToString(format.ToString(),
140 | NumberFormatInfo.InvariantInfo),
141 | charEncoding,
142 | fieldLength,
143 | ALIGN_RIGHT);
144 | }
145 |
146 | public static bool contains(byte[] arr, byte value)
147 | {
148 | return
149 | Array.Exists(arr,
150 | delegate(byte anItem) { return anItem == value; });
151 | }
152 |
153 |
154 | public static Type TypeForNativeDBType(NativeDbType aType)
155 | {
156 | switch (aType)
157 | {
158 | case NativeDbType.Char:
159 | return typeof(string);
160 | case NativeDbType.Date:
161 | return typeof(DateTime);
162 | case NativeDbType.Numeric:
163 | return typeof(decimal);
164 | case NativeDbType.Logical:
165 | return typeof(bool);
166 | case NativeDbType.Float:
167 | return typeof(decimal);
168 | case NativeDbType.Memo:
169 | return typeof(MemoValue);
170 | default:
171 | return typeof(Object);
172 | }
173 | }
174 | }
175 | }
--------------------------------------------------------------------------------
/DotNetDBF/MemoValue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace DotNetDBF
7 | {
8 | public class MemoValue
9 | {
10 | public const string MemoTerminator = "\x1A";
11 | private bool _loaded;
12 | private bool _new;
13 |
14 |
15 | public MemoValue(string aValue)
16 | {
17 | _lockName = $"DotNetDBF.Memo.new.{Guid.NewGuid()}";
18 | Value = aValue;
19 | }
20 |
21 |
22 | internal MemoValue(long block, DBFBase aBase,
23 | string fileLoc, DBFReader.LazyStream fileStream)
24 | {
25 | _block = block;
26 | _base = aBase;
27 | _fileLoc = fileLoc;
28 | _fileStream = fileStream;
29 | if (string.IsNullOrEmpty(fileLoc))
30 | {
31 | _lockName = fileStream();
32 | }
33 | else
34 | {
35 | _lockName = $"DotNetDBF.Memo.read.{_fileLoc}";
36 | }
37 | }
38 |
39 | private readonly DBFBase _base;
40 | private readonly object _lockName;
41 | private long _block;
42 | private readonly string _fileLoc;
43 | private string _value;
44 | private readonly DBFReader.LazyStream _fileStream;
45 |
46 | internal long Block => _block;
47 |
48 | internal void Write(DBFWriter aBase)
49 | {
50 | lock (_lockName)
51 | {
52 | if (!_new)
53 | return;
54 |
55 | var raf = aBase.DataMemo;
56 |
57 | /* before proceeding check whether the passed in File object
58 | is an empty/non-existent file or not.
59 | */
60 | if (raf == null)
61 | {
62 | throw new InvalidDataException("Null Memo Field Stream from Writer");
63 | }
64 |
65 | var tWriter = new BinaryWriter(raf, aBase.CharEncoding); //Don't close the stream could be used else where;
66 |
67 | if (raf.Length == 0)
68 | {
69 | var tHeader = new DBTHeader();
70 | tHeader.Write(tWriter);
71 | }
72 |
73 | var tValue = _value;
74 | if ((tValue.Length + sizeof(int)) % aBase.BlockSize != 0)
75 | {
76 | tValue = tValue + MemoTerminator;
77 | }
78 |
79 | var tPosition = raf.Seek(0, SeekOrigin.End); //Got To End Of File
80 | var tBlockDiff = tPosition % aBase.BlockSize;
81 | if (tBlockDiff != 0)
82 | {
83 | tPosition = raf.Seek(aBase.BlockSize - tBlockDiff, SeekOrigin.Current);
84 | }
85 | _block = tPosition / aBase.BlockSize;
86 | var tData = aBase.CharEncoding.GetBytes(tValue);
87 | var tDataLength = tData.Length;
88 | var tNewDiff = (tDataLength % aBase.BlockSize);
89 | tWriter.Write(tData);
90 | if (tNewDiff != 0)
91 | tWriter.Seek(aBase.BlockSize - (tDataLength % aBase.BlockSize), SeekOrigin.Current);
92 |
93 | }
94 | }
95 |
96 |
97 | public string Value
98 | {
99 | get
100 | {
101 | lock (_lockName)
102 | {
103 | if (_new || _loaded) return _value;
104 | var fileStream = _fileStream();
105 |
106 | var reader = new BinaryReader(fileStream);
107 |
108 | {
109 | reader.BaseStream.Seek(_block * _base.BlockSize, SeekOrigin.Begin);
110 | var builder = new StringBuilder();
111 | int termIndex;
112 | var softReturn = _base.CharEncoding.GetString(new byte[] {0x8d, 0x0a});
113 |
114 | do
115 | {
116 | var data = reader.ReadBytes(_base.BlockSize);
117 | if ((data.Length == 0))
118 | {
119 | throw new DBTException("Missing Data for block or no 1a memo terminator");
120 | }
121 | var stringVal = _base.CharEncoding.GetString(data);
122 | termIndex = stringVal.IndexOf(MemoTerminator, StringComparison.Ordinal);
123 | if (termIndex != -1)
124 | stringVal = stringVal.Substring(0, termIndex);
125 | builder.Append(stringVal);
126 | } while (termIndex == -1);
127 | _value = builder.ToString().Replace(softReturn, string.Empty);
128 | }
129 | _loaded = true;
130 |
131 | return _value;
132 | }
133 | }
134 | set
135 | {
136 | lock (_lockName)
137 | {
138 | _new = true;
139 | _value = value;
140 | }
141 | }
142 | }
143 |
144 | public override int GetHashCode()
145 | {
146 | return _lockName.GetHashCode();
147 | }
148 |
149 | public override string ToString()
150 | {
151 | return Value;
152 | }
153 |
154 | public override bool Equals(object obj)
155 | {
156 | if (obj is MemoValue m)
157 | {
158 | return ReferenceEquals(this, obj) || Value.Equals(m.Value);
159 | }
160 |
161 | return false;
162 | }
163 | }
164 | }
--------------------------------------------------------------------------------
/DotNetDBF/DBFHeader.cs:
--------------------------------------------------------------------------------
1 | /*
2 | DBFHeader
3 | Class for reading the metadata assuming that the given
4 | InputStream carries DBF data.
5 |
6 | This file is part of DotNetDBF packege.
7 |
8 | original author (javadbf): anil@linuxense.com 2004/03/31
9 |
10 | License: LGPL (http://www.gnu.org/copyleft/lesser.html)
11 |
12 | ported to C# (DotNetDBF): Jay Tuley 6/28/2007
13 |
14 |
15 | */
16 |
17 | using System;
18 | using System.Collections.Generic;
19 | using System.IO;
20 |
21 | namespace DotNetDBF
22 | {
23 | [Obsolete("Use DBFSignature instead", error:true)]
24 | public static class DBFSigniture
25 | {
26 | public const byte NotSet = 0,
27 | WithMemo = 0x80,
28 | DBase3 = 0x03,
29 | DBase3WithMemo = DBase3 | WithMemo;
30 | }
31 |
32 | public static class DBFSignature
33 | {
34 | public const byte NotSet = 0,
35 | WithMemo = 0x80,
36 | DBase3 = 0x03,
37 | DBase3WithMemo = DBase3 | WithMemo;
38 | }
39 |
40 | [Flags]
41 | public enum MemoFlags : byte
42 | {
43 | }
44 |
45 |
46 | public class DBFHeader
47 | {
48 | public const byte HeaderRecordTerminator = 0x0D;
49 |
50 | internal byte Signature { get; set; } /* 0 */
51 | internal byte Year { set; get; } /* 1 */
52 | internal byte Month { set; get; } /* 2 */
53 | internal byte Day { set; get; } /* 3 */
54 | internal int NumberOfRecords { set; get; } /* 4-7 */
55 | internal short HeaderLength { set; get; } /* 8-9 */
56 | internal short RecordLength { set; get; } /* 10-11 */
57 | private short _reserv1; /* 12-13 */
58 | private byte _incompleteTransaction; /* 14 */
59 | private byte _encryptionFlag; /* 15 */
60 | private int _freeRecordThread; /* 16-19 */
61 | private int _reserv2; /* 20-23 */
62 | private int _reserv3; /* 24-27 */
63 | private byte _mdxFlag; /* 28 */
64 | internal byte LanguageDriver { get; set; } /* 29 */
65 | private short _reserv4; /* 30-31 */
66 | internal DBFField[] FieldArray { set; get; } /* each 32 bytes */
67 |
68 |
69 | public DBFHeader()
70 | {
71 | Signature = DBFSignature.DBase3;
72 | }
73 |
74 |
75 |
76 | internal short Size => (short) (sizeof(byte) +
77 | sizeof(byte) + sizeof(byte) + sizeof(byte) +
78 | sizeof(int) +
79 | sizeof(short) +
80 | sizeof(short) +
81 | sizeof(short) +
82 | sizeof(byte) +
83 | sizeof(byte) +
84 | sizeof(int) +
85 | sizeof(int) +
86 | sizeof(int) +
87 | sizeof(byte) +
88 | sizeof(byte) +
89 | sizeof(short) +
90 | (DBFField.SIZE * FieldArray.Length) +
91 | sizeof(byte));
92 |
93 | internal short RecordSize
94 | {
95 | get
96 | {
97 | var tRecordLength = 0;
98 | for (var i = 0; i < FieldArray.Length; i++)
99 | {
100 | tRecordLength += FieldArray[i].FieldLength;
101 | }
102 |
103 | return (short) (tRecordLength + 1);
104 | }
105 | }
106 |
107 | internal void Read(BinaryReader dataInput)
108 | {
109 | Signature = dataInput.ReadByte(); /* 0 */
110 | Year = dataInput.ReadByte(); /* 1 */
111 | Month = dataInput.ReadByte(); /* 2 */
112 | Day = dataInput.ReadByte(); /* 3 */
113 | NumberOfRecords = dataInput.ReadInt32(); /* 4-7 */
114 |
115 | HeaderLength = dataInput.ReadInt16(); /* 8-9 */
116 | RecordLength = dataInput.ReadInt16(); /* 10-11 */
117 |
118 | _reserv1 = dataInput.ReadInt16(); /* 12-13 */
119 | _incompleteTransaction = dataInput.ReadByte(); /* 14 */
120 | _encryptionFlag = dataInput.ReadByte(); /* 15 */
121 | _freeRecordThread = dataInput.ReadInt32(); /* 16-19 */
122 | _reserv2 = dataInput.ReadInt32(); /* 20-23 */
123 | _reserv3 = dataInput.ReadInt32(); /* 24-27 */
124 | _mdxFlag = dataInput.ReadByte(); /* 28 */
125 | LanguageDriver = dataInput.ReadByte(); /* 29 */
126 | _reserv4 = dataInput.ReadInt16(); /* 30-31 */
127 |
128 |
129 | var v_fields = new List();
130 |
131 | var field = DBFField.CreateField(dataInput); /* 32 each */
132 | while (field != null)
133 | {
134 | v_fields.Add(field);
135 | field = DBFField.CreateField(dataInput);
136 | }
137 |
138 | FieldArray = v_fields.ToArray();
139 | //System.out.println( "Number of fields: " + _fieldArray.length);
140 | }
141 |
142 | internal void Write(BinaryWriter dataOutput)
143 | {
144 | dataOutput.Write(Signature); /* 0 */
145 | var tNow = DateTime.Now;
146 | Year = (byte) (tNow.Year - 1900);
147 | Month = (byte) (tNow.Month);
148 | Day = (byte) (tNow.Day);
149 |
150 | dataOutput.Write(Year); /* 1 */
151 | dataOutput.Write(Month); /* 2 */
152 | dataOutput.Write(Day); /* 3 */
153 |
154 | //System.out.println( "Number of records in O/S: " + numberOfRecords);
155 | dataOutput.Write(NumberOfRecords); /* 4-7 */
156 |
157 | HeaderLength = Size;
158 | dataOutput.Write(HeaderLength); /* 8-9 */
159 |
160 | RecordLength = RecordSize;
161 | dataOutput.Write(RecordLength); /* 10-11 */
162 |
163 | dataOutput.Write(_reserv1); /* 12-13 */
164 | dataOutput.Write(_incompleteTransaction); /* 14 */
165 | dataOutput.Write(_encryptionFlag); /* 15 */
166 | dataOutput.Write(_freeRecordThread); /* 16-19 */
167 | dataOutput.Write(_reserv2); /* 20-23 */
168 | dataOutput.Write(_reserv3); /* 24-27 */
169 |
170 | dataOutput.Write(_mdxFlag); /* 28 */
171 | dataOutput.Write(LanguageDriver); /* 29 */
172 | dataOutput.Write(_reserv4); /* 30-31 */
173 |
174 | foreach (var field in FieldArray)
175 | {
176 | field.Write(dataOutput);
177 | }
178 |
179 | dataOutput.Write(HeaderRecordTerminator); /* n+1 */
180 | }
181 | }
182 | }
--------------------------------------------------------------------------------
/DotNetDBF.Test/dbfs/dbase_30_summary.txt:
--------------------------------------------------------------------------------
1 |
2 | Database: dbase_30.dbf
3 | Type: (30) Visual FoxPro
4 | Memo File: true
5 | Records: 34
6 |
7 | Fields:
8 | Name Type Length Decimal
9 | ------------------------------------------------------------------------------
10 | ACCESSNO C 15 0
11 | ACQVALUE N 12 2
12 | APPNOTES M 4 0
13 | APPRAISOR C 75 0
14 | CABINET C 25 0
15 | CAPTION C 30 0
16 | CAT C 1 0
17 | CATBY C 25 0
18 | CATDATE D 8 0
19 | CATTYPE C 15 0
20 | CLASSES M 4 0
21 | COLLECTION C 75 0
22 | CONDDATE D 8 0
23 | CONDEXAM C 25 0
24 | CONDITION C 35 0
25 | CONDNOTES M 4 0
26 | CONTAINER C 40 0
27 | COPYRIGHT M 4 0
28 | CREATOR C 80 0
29 | CREDIT M 4 0
30 | CURVALMAX N 12 2
31 | CURVALUE N 12 2
32 | DATASET C 15 0
33 | DATE C 50 0
34 | DESCRIP M 4 0
35 | DIMNOTES M 4 0
36 | DISPVALUE C 10 0
37 | DRAWER C 20 0
38 | EARLYDATE N 4 0
39 | EVENT C 80 0
40 | EXHIBITID C 36 0
41 | EXHIBITNO N 7 0
42 | EXHLABEL1 M 4 0
43 | EXHLABEL2 M 4 0
44 | EXHLABEL3 M 4 0
45 | EXHLABEL4 M 4 0
46 | EXHSTART D 8 0
47 | FILMSIZE C 35 0
48 | FLAGDATE T 8 0
49 | FLAGNOTES M 4 0
50 | FLAGREASON C 20 0
51 | FRAME C 75 0
52 | FRAMENO C 25 0
53 | GPARENT C 45 0
54 | HOMELOC C 60 0
55 | IMAGEFILE C 60 0
56 | IMAGENO N 3 0
57 | INSCOMP C 30 0
58 | INSDATE D 8 0
59 | INSPHONE C 25 0
60 | INSPREMIUM C 20 0
61 | INSREP C 30 0
62 | INSVALUE N 10 2
63 | INVNBY C 25 0
64 | INVNDATE D 8 0
65 | LATEDATE N 4 0
66 | LEGAL M 4 0
67 | LOANCOND M 4 0
68 | LOANDATE D 8 0
69 | LOANDUE D 8 0
70 | LOANID C 36 0
71 | LOANINNO C 15 0
72 | MAINTCYCLE C 10 0
73 | MAINTDATE D 8 0
74 | MAINTNOTE M 4 0
75 | MEDIUM C 75 0
76 | NEGLOC C 60 0
77 | NEGNO C 25 0
78 | NOTES M 4 0
79 | OBJECTID C 25 0
80 | OBJNAME C 40 0
81 | OLDNO C 25 0
82 | ORIGCOPY C 15 0
83 | OTHERNO C 25 0
84 | OUTDATE D 8 0
85 | PARENT C 40 0
86 | PEOPLE M 4 0
87 | PLACE C 100 0
88 | POLICYNO C 20 0
89 | PRINTSIZE C 35 0
90 | PROCESS C 75 0
91 | PROVENANCE M 4 0
92 | PUBNOTES M 4 0
93 | RECAS C 20 0
94 | RECDATE C 10 0
95 | RECFROM C 120 0
96 | RELATION C 36 0
97 | RELNOTES M 4 0
98 | ROOM C 25 0
99 | SGFLAG C 1 0
100 | SHELF C 20 0
101 | SITE C 40 0
102 | SITENO C 12 0
103 | SLIDENO C 25 0
104 | STATUS C 20 0
105 | STATUSBY C 25 0
106 | STATUSDATE D 8 0
107 | STERMS M 4 0
108 | STUDIO C 60 0
109 | SUBJECTS M 4 0
110 | TCABINET C 25 0
111 | TCONTAINER C 40 0
112 | TDRAWER C 20 0
113 | TEMPAUTHOR C 25 0
114 | TEMPBY C 25 0
115 | TEMPDATE D 8 0
116 | TEMPLOC C 60 0
117 | TEMPNOTES M 4 0
118 | TEMPREASON C 50 0
119 | TEMPUNTIL C 10 0
120 | TITLE M 4 0
121 | TITLESORT C 100 0
122 | TROOM C 25 0
123 | TSHELF C 20 0
124 | TWALL C 20 0
125 | UDF1 C 75 0
126 | UDF10 C 75 0
127 | UDF11 C 20 0
128 | UDF12 C 20 0
129 | UDF13 N 12 0
130 | UDF14 N 12 2
131 | UDF15 N 12 2
132 | UDF16 N 12 3
133 | UDF17 N 12 3
134 | UDF18 D 8 0
135 | UDF19 D 8 0
136 | UDF20 D 8 0
137 | UDF21 M 4 0
138 | UDF22 M 4 0
139 | UDF2 C 75 0
140 | UDF3 C 75 0
141 | UDF4 C 75 0
142 | UDF5 C 75 0
143 | UDF6 C 75 0
144 | UDF7 C 75 0
145 | UDF8 C 75 0
146 | UDF9 C 75 0
147 | UPDATED T 8 0
148 | UPDATEDBY C 25 0
149 | VALUEDATE D 8 0
150 | WALL C 20 0
151 | WEBINCLUDE L 1 0
152 | ZSORTER C 69 0
153 | ZSORTERX C 44 0
154 | PPID C 36 0
155 |
--------------------------------------------------------------------------------
/DotNetDBF/original java src/DBFField.java:
--------------------------------------------------------------------------------
1 | /*
2 | DBFField
3 | Class represents a "field" (or column) definition of a DBF data structure.
4 |
5 | This file is part of JavaDBF packege.
6 |
7 | author: anil@linuxense.com
8 | license: LGPL (http://www.gnu.org/copyleft/lesser.html)
9 |
10 | $Id: DBFField.java,v 1.7 2004/03/31 10:50:11 anil Exp $
11 | */
12 |
13 | package com.linuxense.javadbf;
14 | import java.io.*;
15 |
16 | /**
17 | DBFField represents a field specification in an dbf file.
18 |
19 | DBFField objects are either created and added to a DBFWriter object or obtained
20 | from DBFReader object through getField( int) query.
21 |
22 | */
23 | public class DBFField {
24 |
25 | public static final byte FIELD_TYPE_C = (byte)'C';
26 | public static final byte FIELD_TYPE_L = (byte)'L';
27 | public static final byte FIELD_TYPE_N = (byte)'N';
28 | public static final byte FIELD_TYPE_F = (byte)'F';
29 | public static final byte FIELD_TYPE_D = (byte)'D';
30 | public static final byte FIELD_TYPE_M = (byte)'M';
31 |
32 | /* Field struct variables start here */
33 | byte[] fieldName = new byte[ 11]; /* 0-10*/
34 | byte dataType; /* 11 */
35 | int reserv1; /* 12-15 */
36 | int fieldLength; /* 16 */
37 | byte decimalCount; /* 17 */
38 | short reserv2; /* 18-19 */
39 | byte workAreaId; /* 20 */
40 | short reserv3; /* 21-22 */
41 | byte setFieldsFlag; /* 23 */
42 | byte[] reserv4 = new byte[ 7]; /* 24-30 */
43 | byte indexFieldFlag; /* 31 */
44 | /* Field struct variables end here */
45 |
46 | /* other class variables */
47 | int nameNullIndex = 0;
48 |
49 | /**
50 | Creates a DBFField object from the data read from the given DataInputStream.
51 |
52 | The data in the DataInputStream object is supposed to be organised correctly
53 | and the stream "pointer" is supposed to be positioned properly.
54 |
55 | @param in DataInputStream
56 | @return Returns the created DBFField object.
57 | @throws IOException If any stream reading problems occures.
58 | */
59 | protected static DBFField createField( DataInput in)
60 | throws IOException {
61 |
62 | DBFField field = new DBFField();
63 |
64 | byte t_byte = in.readByte(); /* 0 */
65 | if( t_byte == (byte)0x0d) {
66 |
67 | //System.out.println( "End of header found");
68 | return null;
69 | }
70 |
71 | in.readFully( field.fieldName, 1, 10); /* 1-10 */
72 | field.fieldName[0] = t_byte;
73 |
74 | for( int i=0; i 10) {
206 |
207 | throw new IllegalArgumentException( "Field name should be of length 0-10");
208 | }
209 |
210 | this.fieldName = value.getBytes();
211 | this.nameNullIndex = this.fieldName.length;
212 | }
213 |
214 | /**
215 | Sets the data type of the field.
216 |
217 | @param type of the field. One of the following:
218 | C, L, N, F, D, M
219 | */
220 | public void setDataType( byte value) {
221 |
222 | switch( value) {
223 |
224 | case 'D':
225 | this.fieldLength = 8; /* fall through */
226 | case 'C':
227 | case 'L':
228 | case 'N':
229 | case 'F':
230 | case 'M':
231 |
232 | this.dataType = value;
233 | break;
234 |
235 | default:
236 | throw new IllegalArgumentException( "Unknown data type");
237 | }
238 | }
239 |
240 | /**
241 | Length of the field.
242 | This method should be called before calling setDecimalCount().
243 |
244 | @param Length of the field as int.
245 | */
246 | public void setFieldLength( int value) {
247 |
248 | if( value <= 0) {
249 |
250 | throw new IllegalArgumentException( "Field length should be a positive number");
251 | }
252 |
253 | if( this.dataType == FIELD_TYPE_D) {
254 |
255 | throw new UnsupportedOperationException( "Cannot do this on a Date field");
256 | }
257 |
258 | fieldLength = value;
259 | }
260 |
261 | /**
262 | Sets the decimal place size of the field.
263 | Before calling this method the size of the field
264 | should be set by calling setFieldLength().
265 |
266 | @param Size of the decimal field.
267 | */
268 | public void setDecimalCount( int value) {
269 |
270 | if( value < 0) {
271 |
272 | throw new IllegalArgumentException( "Decimal length should be a positive number");
273 | }
274 |
275 | if( value > fieldLength) {
276 |
277 | throw new IllegalArgumentException( "Decimal length should be less than field length");
278 | }
279 |
280 | decimalCount = (byte)value;
281 | }
282 |
283 | }
284 |
--------------------------------------------------------------------------------
/DotNetDBF/original java src/DBFReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | DBFReader
3 | Class for reading the records assuming that the given
4 | InputStream comtains DBF data.
5 |
6 | This file is part of JavaDBF packege.
7 |
8 | Author: anil@linuxense.com
9 | License: LGPL (http://www.gnu.org/copyleft/lesser.html)
10 |
11 | $Id: DBFReader.java,v 1.8 2004/03/31 10:54:03 anil Exp $
12 | */
13 |
14 | package com.linuxense.javadbf;
15 |
16 | import java.io.*;
17 | import java.util.*;
18 |
19 | /**
20 | DBFReader class can creates objects to represent DBF data.
21 |
22 | This Class is used to read data from a DBF file. Meta data and
23 | records can be queried against this document.
24 |
25 |
26 | DBFReader cannot write anythng to a DBF file. For creating DBF files
27 | use DBFWriter.
28 |
29 |
30 | Fetching rocord is possible only in the forward direction and
31 | cannot re-wound. In such situation, a suggested approach is to reconstruct the object.
32 |
33 |
34 | The nextRecord() method returns an array of Objects and the types of these
35 | Object are as follows:
36 |
37 |
38 |
39 | | xBase Type | Java Type |
40 |
41 |
42 |
43 | | C | String |
44 |
45 |
46 | | N | Integer |
47 |
48 |
49 | | F | Double |
50 |
51 |
52 | | L | Boolean |
53 |
54 |
55 | | D | java.util.Date |
56 |
57 |
58 |
59 | */
60 | public class DBFReader extends DBFBase {
61 |
62 | DataInputStream dataInputStream;
63 | DBFHeader header;
64 |
65 | /* Class specific variables */
66 | boolean isClosed = true;
67 |
68 | /**
69 | Initializes a DBFReader object.
70 |
71 | When this constructor returns the object
72 | will have completed reading the hader (meta date) and
73 | header information can be quried there on. And it will
74 | be ready to return the first row.
75 |
76 | @param InputStream where the data is read from.
77 | */
78 | public DBFReader( InputStream in) throws DBFException {
79 |
80 | try {
81 |
82 | this.dataInputStream = new DataInputStream( in);
83 | this.isClosed = false;
84 | this.header = new DBFHeader();
85 | this.header.read( this.dataInputStream);
86 |
87 | /* it might be required to leap to the start of records at times */
88 | int t_dataStartIndex = this.header.headerLength - ( 32 + (32*this.header.fieldArray.length)) - 1;
89 | if( t_dataStartIndex > 0) {
90 |
91 | dataInputStream.skip( t_dataStartIndex);
92 | }
93 | }
94 | catch( IOException e) {
95 |
96 | throw new DBFException( e.getMessage());
97 | }
98 | }
99 |
100 |
101 | public String toString() {
102 |
103 | StringBuffer sb = new StringBuffer( this.header.year + "/" + this.header.month + "/" + this.header.day + "\n"
104 | + "Total records: " + this.header.numberOfRecords +
105 | "\nHEader length: " + this.header.headerLength +
106 | "");
107 |
108 | for( int i=0; i 0 && !Utils.contains( t_float, (byte)'?')) {
242 |
243 | recordObjects[i] = new Float( new String( t_float));
244 | }
245 | else {
246 |
247 | recordObjects[i] = null;
248 | }
249 | }
250 | catch( NumberFormatException e) {
251 |
252 | throw new DBFException( "Failed to parse Float: " + e.getMessage());
253 | }
254 |
255 | break;
256 |
257 | case 'N':
258 |
259 | try {
260 |
261 | byte t_numeric[] = new byte[ this.header.fieldArray[i].getFieldLength()];
262 | dataInputStream.read( t_numeric);
263 | t_numeric = Utils.trimLeftSpaces( t_numeric);
264 |
265 | if( t_numeric.length > 0 && !Utils.contains( t_numeric, (byte)'?')) {
266 |
267 | recordObjects[i] = new Double( new String( t_numeric));
268 | }
269 | else {
270 |
271 | recordObjects[i] = null;
272 | }
273 | }
274 | catch( NumberFormatException e) {
275 |
276 | throw new DBFException( "Failed to parse Number: " + e.getMessage());
277 | }
278 |
279 | break;
280 |
281 | case 'L':
282 |
283 | byte t_logical = dataInputStream.readByte();
284 | if( t_logical == 'Y' || t_logical == 't' || t_logical == 'T' || t_logical == 't') {
285 |
286 | recordObjects[i] = Boolean.TRUE;
287 | }
288 | else {
289 |
290 | recordObjects[i] = Boolean.FALSE;
291 | }
292 | break;
293 |
294 | case 'M':
295 | // TODO Later
296 | recordObjects[i] = new String( "null");
297 | break;
298 |
299 | default:
300 | recordObjects[i] = new String( "null");
301 | }
302 | }
303 | }
304 | catch( EOFException e) {
305 |
306 | return null;
307 | }
308 | catch( IOException e) {
309 |
310 | throw new DBFException( e.getMessage());
311 | }
312 |
313 | return recordObjects;
314 | }
315 | }
316 |
--------------------------------------------------------------------------------
/DotNetDBF.Test/dbfs/dbase_03.dbf:
--------------------------------------------------------------------------------
1 |
N Point_ID C Type C Shape C Circular_D C Non_circul C <