public void writeToShapefile( ShapefileDataStore dataStore, FeatureCollection<SimpleFeatureType, SimpleFeature> collection )
throws IOException {
String featureName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(featureName);
Transaction transaction = new DefaultTransaction("create");
try {
FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource;
featureStore.setTransaction(transaction);
featureStore.addFeatures(collection);
transaction.commit();
} catch (Exception eek) {
transaction.rollback();
throw new IOException("The transaction could now be finished, an error orrcurred", eek);
} finally {
transaction.close();
}
}