César Martínez Izquierdo ha scritto:
> Yesterday I sent this to user's list, but I think is most suitable here.
> Note that I've created a patch which solves the problem, please have a
> look at it.
> I've been working on 2.5.x branch.
> 
> Original message:
> ----------
> 
> Hello list,
> I'm writing a DBF file using a code like this:
> 
>  DbaseFileHeader header = getHeader();
>  WritableByteChannel out = new FileOutputStream(filename).getChannel();
>  DbaseFileWriter writer = new DbaseFileWriter(header, out);
>  for (int i=0; i<NUMROWS; i++) {
>    writer.write(getRow());
>  }
>  writer.close();
> 
> I'd expect that when I close the file, the number of registers gets
> updated in the DBF header.
> 
> However, it seems that it is not actually updated and the header ends
> with a value of 0 (zero) registers, which means that
> DbaseFileReader.hasNext() will always return false for this file.
> 
> This is a pity, it means I can't write a proper DBF unless I know the
> number of registers in advance.
> Am I missing something here?

Well... the thing these classes are not really meant to be used directly.
What the GeoTools code does it to keep count of the records
separately and call dbfHeader.writeHeader directly before closing
the file.
See ShapefileFeatureWriter.flush().

Writing the header each time a record is written seems like
a very big waste of time, it may make the disk head spin a lot
between the two positions: this will happen only on on bigger
shapefiles and will get worse as the dbf file grows, and will
also depend on whether you have writeback enabled or not but...
yeah, it sound like bad practice to me.

If you want to make it easier to use the patch could look into recording
the number of records in a field and then have the close method
(or add a flush method) that does write out the header.

Cheers
Andrea

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to