use of com.baremaps.stream.StreamException in project baremaps by baremaps.
the class CreateGeometryConsumer method createLine.
private LineString createLine(Member member) {
try {
List<Long> refs = this.references.get(member.getRef());
List<Coordinate> coords = refs.stream().map(coordinates::get).collect(Collectors.toList());
Coordinate[] array = coords.toArray(new Coordinate[coords.size()]);
return geometryFactory.createLineString(array);
} catch (Exception e) {
throw new StreamException(e);
}
}
use of com.baremaps.stream.StreamException in project baremaps by baremaps.
the class OsmChangeSpliterator method tryAdvance.
@Override
public boolean tryAdvance(Consumer<? super Change> consumer) {
try {
if (reader.hasNext()) {
int event = reader.next();
switch(event) {
case START_ELEMENT:
if (ELEMENT_NAME_OSMCHANGE.equals(reader.getLocalName())) {
return true;
}
Change entity = readChange();
consumer.accept(entity);
return true;
case END_DOCUMENT:
return false;
default:
return true;
}
} else {
return false;
}
} catch (XMLStreamException e) {
throw new StreamException(e);
}
}
use of com.baremaps.stream.StreamException in project baremaps by baremaps.
the class Execute method call.
@Override
public Integer call() throws Exception {
DataSource datasource = PostgresUtils.datasource(database);
BlobStore blobStore = options.blobStore();
for (URI file : files) {
logger.info("Execute {}", file);
String blob = new String(blobStore.get(file).getInputStream().readAllBytes(), StandardCharsets.UTF_8);
blob = interpolate(System.getenv(), blob);
StreamUtils.batch(Splitter.on(";").splitToStream(blob), 1).forEach(query -> {
try (Connection connection = datasource.getConnection();
Statement statement = connection.createStatement()) {
statement.execute(query);
} catch (SQLException e) {
throw new StreamException(e);
}
});
}
logger.info("Done");
return 0;
}
use of com.baremaps.stream.StreamException in project baremaps by baremaps.
the class OsmPbfParser method entities.
/**
* Creates an ordered stream of entities.
*
* @param inputStream an osm pbf {@link InputStream}
* @return a stream of blocks
*/
public Stream<Entity> entities(InputStream inputStream) {
return blocks(inputStream).flatMap(block -> {
try {
Stream.Builder<Entity> entities = Stream.builder();
block.visit(new BlockEntityConsumer(entities::add));
return entities.build();
} catch (Exception e) {
throw new StreamException(e);
}
});
}
use of com.baremaps.stream.StreamException in project baremaps by baremaps.
the class OsmChangeSpliterator method readChange.
private Change readChange() throws XMLStreamException {
switch(reader.getLocalName()) {
case ELEMENT_NAME_CREATE:
case ELEMENT_NAME_DELETE:
case ELEMENT_NAME_MODIFY:
ChangeType type = ChangeType.valueOf(reader.getLocalName().toUpperCase());
List<Entity> elements = new ArrayList<>();
reader.nextTag();
while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
elements.add(readElement());
reader.nextTag();
}
return new Change(type, elements);
default:
throw new StreamException("Unexpected XML element: " + reader.getLocalName());
}
}
Aggregations