DataStore store = DataStoreFinder.getDataStore(params);
final SimpleFeatureType type = store.getSchema("example");
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
SimpleFeature f;
DefaultFeatureCollection collection = new DefaultFeatureCollection();
f = SimpleFeatureBuilder
.build(type, new Object[] { 1, "jody" }, "fid1");
collection.add(f);
f = SimpleFeatureBuilder.build(type, new Object[] { 2, "brent" },
"fid3");
collection.add(f);
f = SimpleFeatureBuilder
.build(type, new Object[] { 3, "dave" }, "fid3");
collection.add(f);
f = SimpleFeatureBuilder.build(type, new Object[] { 4, "justin" },
"fid4");
collection.add(f);
writer = store.getFeatureWriter("road", Transaction.AUTO_COMMIT);
try {
// remove all features
while (writer.hasNext()) {
writer.next();
writer.remove();
}
// copy new features in
SimpleFeatureIterator iterator = collection.features();
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
SimpleFeature newFeature = writer.next(); // new blank feature
newFeature.setAttributes(feature.getAttributes());
writer.write();