package uk.ac.leeds.ccg.dbffile; import uk.ac.leeds.ccg.geotools.*; import uk.ac.leeds.ccg.geotools.misc.*; import java.util.*; import java.io.*; import cmp.LEDataStream.*; /** a class for writing dbf files * @author Ian Turton */ public class DbfFileWriter implements DbfConsts{ private final static boolean DEBUG=true; private final static String DBC="DbFW>"; int NoFields =1; int NoRecs = 0; int recLength = 0; DbfFieldDef fields[]; LEDataOutputStream ls; private boolean header = false; public DbfFileWriter(String file) throws IOException{ if(DEBUG)System.out.println("---->uk.ac.leeds.ccg.dbffile.DbfFileWriter constructed. Will identify itself as "+DBC); ls = new LEDataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); } public void writeHeader(DbfFieldDef f[], int nrecs) throws IOException{ NoFields = f.length; NoRecs = nrecs; fields = new DbfFieldDef[NoFields]; for(int i=0;i" +gds[k].getDataType()+"*"); switch(type){ case GeoData.INTEGER: ct = 'N'; df[k] = new DbfFieldDef(gds[k].getName().trim(),ct,width,0); break; case GeoData.CHARACTER: ct = 'C'; df[k] = new DbfFieldDef(gds[k].getName().trim(),ct,width,0); break; case GeoData.FLOATING: ct = 'F'; df[k] = new DbfFieldDef(gds[k].getName().trim(),ct,width+dp+1,dp); break; default: throw new DbfFileException("No data type set in geodata "+gds[k].getName()); } if(DEBUG)System.out.println(DBC+df[k]); } //width = (int)Math.ceil(Math.log(gds[0].getSize())/Math.log(10.0)); //System.out.println(DBC+" id width "+width); //df[0] = new DbfFieldDef("ID",'N',width,0); // write the header writeHeader(df,gds[0].getSize()); // write the records if(DEBUG)System.out.println(DBC+"writeGeoDatas writing "+gds[0].getSize() +" records"); Integer id=null; Vector rec=new Vector(gds.length); Enumeration e = gds[0].getIds(); while(e.hasMoreElements()){ id=(Integer)e.nextElement(); //rec.add(0,id); for(int k=0;k