FeatureCollectionExport { public boolean writeToShapefile() throws MalformedURLException, IOException { boolean success = false; SimpleFeatureType type = buildFeatureType(); FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp"); File shpFile = checkAndCreateFile(); Map datastoreConfig = new HashMap<>(); datastoreConfig.put("url", shpFile.toURI().toURL()); ShapefileDataStore shpfileDataStore = (ShapefileDataStore)factory.createNewDataStore(datastoreConfig); shpfileDataStore.createSchema(type); shpfileDataStore.forceSchemaCRS(this.crs); SimpleFeatureStore featureStore = (SimpleFeatureStore) shpfileDataStore.getFeatureSource(type.getName()); Transaction t = new DefaultTransaction(); SimpleFeatureIterator fi = null; try { featureStore.setTransaction(t); fi = simpleFeatureCollection.features(); SimpleFeatureBuilder fb = new SimpleFeatureBuilder(type); while (fi.hasNext()) { SimpleFeature source = fi.next(); fb.reset(); for (AttributeDescriptor desc : type.getAttributeDescriptors()) { Name attributeName = desc.getName(); Object attributeValue = source.getAttribute(attributeName); if(null == attributeValue){ attributeValue = NULL_PLACEHOLDER; } fb.set(attributeName, attributeValue); } SimpleFeature target = fb.buildFeature(null); featureStore.addFeatures(DataUtilities.collection(target)); } success = true; } finally { t.commit(); t.close(); IOUtils.closeQuietly(fi); } return success; } FeatureCollectionExport(SimpleFeatureCollection simpleFeatureCollection,
            File outputDirectory, String namePrefix);  FeatureCollectionExport(SimpleFeatureCollection simpleFeatureCollection,
            File outputDirectory, String namePrefix, boolean downloadAll); void addAttribute(String attrName); void setCRS(CoordinateReferenceSystem crs); boolean writeToShapefile(); static final CoordinateReferenceSystem DEFAULT_CRS; static final int NULL_PLACEHOLDER; }
@Test @Ignore public void testWriteToShapefile() throws Exception { WFSDataStoreFactory datastore = new WFSDataStoreFactory(); Map params = new HashMap<>(); params.put(WFSDataStoreFactory.URL.key, new URL("http: params.put(WFSDataStoreFactory.WFS_STRATEGY.key, "arcgis"); params.put(WFSDataStoreFactory.TIMEOUT.key, 15000); params.put(WFSDataStoreFactory.TRY_GZIP.key, "true"); WFSDataStore wfs = datastore.createDataStore(params); String[] typeNames = wfs.getTypeNames(); SimpleFeatureSource featureSource = wfs.getFeatureSource(typeNames[2]); FeatureCollectionExport featureCollectionExport = new FeatureCollectionExport(featureSource.getFeatures(), new File("/tmp/shpfile"), "test3"); featureCollectionExport.addAttribute("CVIRISK"); featureCollectionExport.writeToShapefile(); }