Please keep in mind that a SimpleFeatureCollection is similar to a result set; and may not necessarily load everything in to memory. Treat each iterator as a forward only cursor in the JDBC sense; and take care to FeatureIterator.close() after use.
SimpleFeatureCollection provides streaming access with the following restrictions on use of {@link SimpleFeatureIterator}: You must call {@link SimpleFeatureIterator#close()}. This allows FeatureCollection to clean up any operating system resources used to access information.
Example (safe) use:
SimpleFeatureIterator iterator = simpleFeatureCollection.features(); try { while( iterator.hasNext() ){ SimpleFeature feature = iterator.next(); System.out.println( feature.getID() ); } } finally { iterator.close(); }
And in Java 7: try ( SimpleFeatureIterator iterator = simpleFeatureCollection.features() ){ while( iterator.hasNext() ){ SimpleFeature feature = iterator.next(); System.out.println( feature.getID() ); } }
@source $URL$
|
|