diff --git a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java index 58cdf28924438ef18243b99fa83307d82bd5418f..2bfd26b1b01fa3274ac24c417f3ca9985953bacd 100644 --- a/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java +++ b/CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/parser/CityGmlParser.java @@ -196,6 +196,41 @@ public class CityGmlParser { } } + public static CityDoctorModel parseCityGmlStream(InputStream is, ParserConfiguration config) + throws CityGmlParseException, InvalidGmlFileException { + return parseCityGmlStream(is, config, null, null); + } + + public static CityDoctorModel parseCityGmlStream(InputStream is, ParserConfiguration config, ProgressListener l) + throws CityGmlParseException, InvalidGmlFileException { + return parseCityGmlStream(is, config, l, null); + } + + public static CityDoctorModel parseCityGmlStream(InputStream is, ParserConfiguration config, ProgressListener l, + GMLValidationHandler handler) throws CityGmlParseException, InvalidGmlFileException { + CityGMLContext context = getContext(); + + if (config.getValidate()) { + //TODO: Think of something to validate Inputstream + throw new InvalidGmlFileException("Invalid GML File."); + } + + try { + parseEpsgCodeFromStream(is, config); + CityGMLInputFactory in = context.createCityGMLInputFactory() + .withChunking(ChunkOptions.chunkByProperties(chunkProperties).skipCityModel(false)); + try(ObservedInputStream ois = new ObservedInputStream(is, is.available())){ + if (l != null){ + ois.addListener(l::updateProgress); + } + return readAndKeepFeatures(config, Path.of(""), in, ois); + } + } catch (CityGMLReadException | IOException | ParserConfigurationException | SAXException e) { + logger.error(e); + throw new CityGmlParseException("Failed to read CityGML file", e); + } + } + public static void streamCityGml(String file, ParserConfiguration config, CityGmlConsumer cityObjectConsumer, String outputFile) throws CityGmlParseException { Path f = Paths.get(file);