ru.smartflex.tools.dbf
Class DbfEngine

java.lang.Object
  extended by ru.smartflex.tools.dbf.DbfEngine

public class DbfEngine
extends java.lang.Object

The main class that supplies iterators and appenders - start here.

The reader parts may be used in two ways:

  1. to get iterator directly:
     DbfIterator dbfIterator = DbfEngine.getReader(
                    Fp26Reader.class.getResourceAsStream("FP_26_SAMPLE.DBF"), null);
     
  2. first to get dbf header definition and then get iterator:
     DbfHeader dbfHeader = DbfEngine.getHeader(
                    Fp26Reader.class.getResourceAsStream("FP_26_SAMPLE.DBF"), null);
     DbfIterator dbfIterator = dbfHeader.getDbfIterator();
     
Then you have to read dbf data in cycle like as:
 while (dbfIterator.hasMoreRecords()) {
        DbfRecord dbfRecord = dbfIterator.nextRecord();
        String string = dbfRecord.getString("string");
        float sumFloat = dbfRecord.getFloat("sum_f");
        BigDecimal sumNumeric = dbfRecord.getBigDecimal("sum_n");
        boolean bool = dbfRecord.getBoolean("bool_val");
        Date date = dbfRecord.getDate("date_val");
        System.out.println(string + " " + sumFloat + " " + sumNumeric + " " + bool
                        + " " + date);
 }
 

The writer parts may be used in one way:

First: you have to get DbfAppender:
 DbfAppender dbfAppender = DbfEngine.getWriter("WRT_PERSON.DBF",
                DbfCodePages.Cp866);
 
And then you have to define columns for dbf header:
 DbfColumn dc01 = new DbfColumn("magic", DbfColumnTypes.Logical, 0, 0);
 DbfColumn dc02 = new DbfColumn("actor", DbfColumnTypes.Character, 60, 0);
 DbfColumn dc03 = new DbfColumn("currdate", DbfColumnTypes.Date, 0, 0);
 DbfColumn dc04 = new DbfColumn("hit", DbfColumnTypes.Numeric, 10, 2);
 DbfColumn dc05 = new DbfColumn("forever", DbfColumnTypes.Logical, 0, 0);
 
 dbfAppender.defineColumns(dc01, dc02, dc03, dc04, dc05);
 
After that you have to use DbfStatement:
 DbfStatement statement = dbfAppender.getStatement();
 
statement.setString("actor", "Chuck Norris"); statement.setDate("currdate", new Date()); statement.setBigDecimal("hit", new BigDecimal("500.5"));
statement.insertStatement();
statement.setBoolean("magic", Boolean.TRUE); statement.setString("actor", "Bruce Lee"); statement.setBigDecimal("hit", new BigDecimal("1000.10")); statement.setBoolean("forever", Boolean.TRUE);
statement.insertStatement();
dbfAppender.writeDbfAndClose();

Since:
1.00
Author:
galisha

Method Summary
static DbfHeader getHeader(java.io.File dbfFile, java.lang.String enc)
          Gets DBF header.
static DbfHeader getHeader(java.io.InputStream dbfStream, java.lang.String enc)
          Gets DBF header.
static DbfHeader getHeader(java.lang.String dbfFileName, java.lang.String enc)
          Gets DBF header.
static DbfHeader getHeader(java.lang.String path, java.lang.String dbfFileName, java.lang.String enc)
          Gets DBF header.
static DbfIterator getReader(java.io.File dbfFile, java.lang.String enc)
          Gets DBF iterator
static DbfIterator getReader(java.io.InputStream dbfStream, java.lang.String enc)
          Gets DBF iterator
static DbfIterator getReader(java.lang.String dbfFileName, java.lang.String enc)
          Gets DBF iterator
static DbfIterator getReader(java.lang.String path, java.lang.String dbfFileName, java.lang.String enc)
          Gets DBF iterator
static DbfAppender getWriter(java.io.File dbfFile, DbfCodePages dbfCodePage)
          Gets DBF appender
static DbfAppender getWriter(java.io.OutputStream dbfStream, DbfCodePages dbfCodePage)
          Gets DBF appender
static DbfAppender getWriter(java.lang.String dbfFileName, DbfCodePages dbfCodePage)
          Gets DBF appender
static DbfAppender getWriter(java.lang.String path, java.lang.String dbfFileName, DbfCodePages dbfCodePage)
          Gets DBF appender
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getHeader

public static DbfHeader getHeader(java.lang.String dbfFileName,
                                  java.lang.String enc)
Gets DBF header.

Parameters:
dbfFileName -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
dbf header
Since:
1.05

getHeader

public static DbfHeader getHeader(java.lang.String path,
                                  java.lang.String dbfFileName,
                                  java.lang.String enc)
Gets DBF header.

Parameters:
path -
dbfFileName -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
dbf header
Since:
1.05

getHeader

public static DbfHeader getHeader(java.io.File dbfFile,
                                  java.lang.String enc)
Gets DBF header.

Parameters:
dbfFile -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
dbf header
Since:
1.05

getHeader

public static DbfHeader getHeader(java.io.InputStream dbfStream,
                                  java.lang.String enc)
Gets DBF header.

Parameters:
dbfStream -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
dbf header
Since:
1.05

getReader

public static DbfIterator getReader(java.lang.String dbfFileName,
                                    java.lang.String enc)
Gets DBF iterator

Parameters:
dbfFileName -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
Since:
1.00

getReader

public static DbfIterator getReader(java.lang.String path,
                                    java.lang.String dbfFileName,
                                    java.lang.String enc)
Gets DBF iterator

Parameters:
path -
dbfFileName -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
Since:
1.00

getReader

public static DbfIterator getReader(java.io.File dbfFile,
                                    java.lang.String enc)
Gets DBF iterator

Parameters:
dbfFile -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
Since:
1.00

getReader

public static DbfIterator getReader(java.io.InputStream dbfStream,
                                    java.lang.String enc)
Gets DBF iterator

Parameters:
dbfStream -
enc - If codepage in dbf file is missed(in other words == null) then this parameter filled as Cp866
Returns:
Since:
1.00

getWriter

public static DbfAppender getWriter(java.lang.String path,
                                    java.lang.String dbfFileName,
                                    DbfCodePages dbfCodePage)
Gets DBF appender

Parameters:
path -
dbfFileName -
dbfCodePage -
Returns:
Since:
1.00

getWriter

public static DbfAppender getWriter(java.lang.String dbfFileName,
                                    DbfCodePages dbfCodePage)
Gets DBF appender

Parameters:
dbfFileName -
dbfCodePage -
Returns:
Since:
1.00

getWriter

public static DbfAppender getWriter(java.io.File dbfFile,
                                    DbfCodePages dbfCodePage)
Gets DBF appender

Parameters:
dbfFile -
dbfCodePage -
Returns:
Since:
1.00

getWriter

public static DbfAppender getWriter(java.io.OutputStream dbfStream,
                                    DbfCodePages dbfCodePage)
Gets DBF appender

Parameters:
dbfStream -
dbfCodePage -
Returns:
Since:
1.00