Hi Sebastian I am not sure how well maintained VPF is ...

FeatureReader is a single use class; so the getCount method is going to 
create one; use it; and then close it.
FeatureCollection is a multi use class; it will create one or more 
FeatureReaders as needed to handle the various requests like size(), 
iterator() etc...

> Hi everyone,
>
> I’m trying to read some VMAP-Data with the VPFLibrary and encountered 
> a strange behaviour in the DefaultFeatureResults -Class.
>
> After reading data from the Library like this:
>
> /VPFLibrary lib = *new* VPFLibrary(library);/
>
> / /
>
> /String[] types = lib.getTypeNames();/
>
> */for/*/ (*int* i = 0; i < types.length; i++)/
>
> /{/
>
> / String featureTypeName = types[i];/
>
> / System.out.println("###################");/
>
> /System.out..println("TypeName: " + featureTypeName);/
>
> / FeatureSource featureSource = lib.getFeatureSource(featureTypeName);/
>
> / FeatureType type = featureSource.getSchema();/
>
> / FeatureCollection coll = featureSource.getFeatures();/
>
> / System.out.println("FeatureSize: " + coll.size());/
>
> / Iterator<Feature> it = coll.iterator();/
>
> / System.out.println("Features:");/
>
> / *while*(it.hasNext()) {/
>
> / Feature f = it.next();/
>
> / System.out.println(f.toString());/
>
> / }/
>
> /}/
>
Note the above code is bad; it should say:
try {
///
}
finally {
coll.close( it );
}
So the iterator manages to close the feature reader it is using.
>
> //
>
> the DefaultFeatureResults(a DefaultFeatureCollection) closed the 
> FeatureReader in its getCount()-Routine:
>
> */int/*/ count;/
>
> /count = featureSource.getCount(query);/
>
> / /
>
> */if/*/ (count != -1) {/
>
> / // we have an optimization!/
>
> / *return* count;/
>
> /}/
>
> / /
>
> /// Okay lets count the FeatureReader/
>
> */try/*/ {/
>
> / count = 0;/
>
> / /
>
> / FeatureReader reader = reader();/
>
> / /
>
> / *for* (; reader.hasNext(); count++) {/
>
> / reader.next();/
>
> / }/
>
> / /
>
> / reader.close();// //Why does it close the Reader?/
>
> / /
>
> / *return* count;/
>
> /} *catch* (IllegalAttributeException e) {/
>
> / *throw* *new* DataSourceException("Could not read feature ", e);/
>
> /}/
>
> the FeatureReader then closed all Filehandles in its reset()-Routine 
> (which is called by close()):
>
This one should use try / finally as well or we would have a file handle 
leak.
>
> /VPFFile file = (VPFFile) 
> featureType.getFeatureClass().getFileList().get(0);/
>
> /file.reset();/
>
> /VPFFileFactory.getInstance().reset(); //This closes all Handles/
>
> the Handles were not opened again and thus the following error occurred:
>
Interesting; the DataStore close method has been added; perhaps we could 
move the closing of file handles there. Allowing FeatureReaders to reuse 
existing file handles as needed? Shapefile datastore just did something 
similar on trunk.

The FeatureReaders should be responsible for making their own file 
handle the first time next(); is called ... this is why they can throw 
an IOException. The idea is that *nothing* happens with the file until 
reader.next() is called for the first time. That way geotools stays 
light bright and sparkling.

Hope this helps; and if you have commit access go ahead and clean up the 
VPF code you found.
Jody


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to