use of org.geotoolkit.nio.PosixDirectoryFilter in project geotoolkit by Geomatys.
the class GMLSparseStore method getType.
@Override
public synchronized FeatureType getType() throws DataStoreException {
if (featureType == null) {
final String xsd = parameters.getValue(GMLProvider.XSD);
final String xsdTypeName = parameters.getValue(GMLProvider.XSD_TYPE_NAME);
catalog = new GenericNameIndex();
if (xsd != null) {
// read types from XSD file
final JAXBFeatureTypeReader reader = new JAXBFeatureTypeReader();
try {
catalog = reader.read(new URL(xsd));
featureType = catalog.get(xsdTypeName);
} catch (MalformedURLException | JAXBException ex) {
throw new DataStoreException(ex.getMessage(), ex);
}
} else {
final JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
reader.getProperties().put(JAXPStreamFeatureReader.LONGITUDE_FIRST, longitudeFirst);
reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
try {
if (Files.isDirectory(file)) {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(file, new PosixDirectoryFilter("*.gml", true))) {
final Iterator<Path> gmlPaths = directoryStream.iterator();
// get first gml file only
if (gmlPaths.hasNext()) {
final Path gmlPath = gmlPaths.next();
try (FeatureReader ite = reader.readAsStream(gmlPath)) {
catalog = reader.getFeatureTypes();
featureType = ite.getFeatureType();
}
}
}
} else {
try (FeatureReader ite = reader.readAsStream(file)) {
catalog = reader.getFeatureTypes();
featureType = ite.getFeatureType();
}
}
} catch (IOException | XMLStreamException ex) {
throw new DataStoreException(ex.getMessage(), ex);
} finally {
reader.dispose();
}
}
}
return featureType;
}
Aggregations