Hello,

My program successfully reads features from a shapefile. At some point, long 
after the shapefile was read, I get the following message in my console:

org.geotools.data.shapefile.ShapefileFeatureReader finalize
WARNING: There is code leaving shapefile readers unclosed, this might result in 
file system locks not being cleared.

I tried closing the ShapefileFeatureReader instance manually but there is no 
“close” method available. Calling “dispose” does not help. Looking at the 
GeoTools code[1] (line 298), a “close” method is defined but code outside the 
package cannot call it.

This is how I read shapefiles:

public static SimpleFeatureCollection fromShapefile(String pathname) throws 
Exception {
        File file = new File(pathname);

        Map<String, Serializable> connectionParameters = new HashMap<>();
        connectionParameters.put("url", file.toURI().toURL());
        DataStore dataStore = 
DataStoreFinder.getDataStore(connectionParameters);

        String[] featureTypes = dataStore.getTypeNames();
        if (featureTypes.length != 1) {
                throw new Exception();
        }

        SimpleFeatureSource featureSource = 
dataStore.getFeatureSource(featureTypes[0]);
        SimpleFeatureCollection features = featureSource.getFeatures();
        dataStore.dispose();
        return features;
}

Is this the correct way to do it?

My console gets spammed by the warning message and makes it difficult to read 
the console output my program generates. Is there anything I can do to disable 
warning messages by GeoTools?

Christian

[1] 
https://github.com/geotools/geotools/blob/master/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/ShapefileFeatureReader.java#L298-L321
------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to