DbaseFileWriter and number of registers

5 messages Options
Embed this post
Permalink
César Martínez Izquierdo-3

DbaseFileWriter and number of registers

Reply Threaded More More options
Print post
Permalink
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?

Regards,

César


--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   César Martínez Izquierdo
   GIS developer
   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
   ETC-LUSI: http://etc-lusi.eionet.europa.eu/
   Universitat Autònoma de Barcelona (SPAIN)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

DbaseFileWriter.java.patch (2K) Download Attachment
aaime

Re: DbaseFileWriter and number of registers

Reply Threaded More More options
Print post
Permalink
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-devel
César Martínez Izquierdo-3

Re: DbaseFileWriter and number of registers

Reply Threaded More More options
Print post
Permalink
2009/10/17 Andrea Aime <[hidden email]>:
[SNIP]
> 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.
>

Hello Andreas, that is exactly what my patch does (just writing the
header in the close method).
Would you consider including this changes in GeoTools?

Best regards,

César


--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   César Martínez Izquierdo
   GIS developer
   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
   ETC-LUSI: http://etc-lusi.eionet.europa.eu/
   Universitat Autònoma de Barcelona (SPAIN)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-devel
aaime

Re: DbaseFileWriter and number of registers

Reply Threaded More More options
Print post
Permalink
César Martínez Izquierdo ha scritto:

> 2009/10/17 Andrea Aime <[hidden email]>:
> [SNIP]
>> 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.
>>
>
> Hello Andreas, that is exactly what my patch does (just writing the
> header in the close method).
> Would you consider including this changes in GeoTools?
>

As sorry, I misread your patch. Yeah, I will have a look about
integrating it. No promises on when, this week we have FOSS4G going
and we're all busy with it.

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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-devel
César Martínez Izquierdo-3

Re: DbaseFileWriter and number of registers

Reply Threaded More More options
Print post
Permalink
El día 18 de octubre de 2009 23:33, Andrea Aime <[hidden email]> escribió:

[SNIP]

> As sorry, I misread your patch. Yeah, I will have a look about integrating
> it. No promises on when, this week we have FOSS4G going
> and we're all busy with it.
>
> Cheers
> Andrea
>

OK, I'll be patient. I've opened an issue in JIRA so that it doesn't
get forgotten:
http://jira.codehaus.org/browse/GEOT-2794

Regards,

César


--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   César Martínez Izquierdo
   GIS developer
   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
   ETC-LUSI: http://etc-lusi.eionet.europa.eu/
   Universitat Autònoma de Barcelona (SPAIN)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-devel