source: osm/applications/editors/josm/plugins/reverter/src/reverter/MultiOsmReader.java@ 35078

Last change on this file since 35078 was 35078, checked in by upliner, 5 years ago

Reverter: Update MultiOsmReader to support null data after redaction

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package reverter;
3
4import java.io.InputStream;
5import java.io.InputStreamReader;
6
7import javax.xml.stream.XMLStreamException;
8
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.Relation;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.io.IllegalDataException;
13import org.openstreetmap.josm.io.OsmReader;
14import org.openstreetmap.josm.io.UTFInputStreamReader;
15import org.openstreetmap.josm.tools.XmlUtils;
16
17/**
18 * Subclass of {@link org.openstreetmap.josm.io.OsmReader} that can handle multiple XML streams.
19 *
20 */
21public class MultiOsmReader extends OsmReader {
22
23 /**
24 * Parse data in source and add to existing dataset.
25 * @param source the input stream with OSM data
26 * @throws IllegalDataException in case of any exception
27 */
28 public void addData(InputStream source) throws IllegalDataException {
29 try (InputStreamReader ir = UTFInputStreamReader.create(source)) {
30 setParser(XmlUtils.newSafeXMLInputFactory().createXMLStreamReader(ir));
31 parse();
32 } catch (Exception e) {
33 throw new IllegalDataException(e);
34 }
35 }
36
37 public void processData() throws IllegalDataException {
38 prepareDataSet();
39 }
40
41 public ParseCallback callback;
42
43 @Override
44 protected Node parseNode() throws XMLStreamException {
45 Node node = super.parseNode();
46 if (callback != null) {
47 callback.primitiveParsed(node.getPrimitiveId());
48 }
49 return node;
50 }
51 @Override
52 protected Way parseWay() throws XMLStreamException {
53 Way way = super.parseWay();
54 if (callback != null) {
55 callback.primitiveParsed(way.getPrimitiveId());
56 }
57 return way;
58 }
59 @Override
60 protected Relation parseRelation() throws XMLStreamException {
61 Relation relation = super.parseRelation();
62 if (callback != null) {
63 callback.primitiveParsed(relation.getPrimitiveId());
64 }
65 return relation;
66 }
67}
Note: See TracBrowser for help on using the repository browser.