use of de.topobyte.osm4j.core.model.iface.EntityContainer in project osm4j-pbf by topobyte.
the class Util method copyAndRead.
public static void copyAndRead(String resource, boolean readMetadata, boolean writeMetadata) throws IOException {
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
OsmIterator iterator = new PbfIterator(input, readMetadata);
File file = File.createTempFile("osm4j-test", "pbf");
OutputStream output = new FileOutputStream(file);
OsmOutputStream osmOutput = new PbfWriter(output, writeMetadata);
for (EntityContainer container : iterator) {
switch(container.getType()) {
default:
case Node:
osmOutput.write((OsmNode) container.getEntity());
break;
case Way:
osmOutput.write((OsmWay) container.getEntity());
break;
case Relation:
osmOutput.write((OsmRelation) container.getEntity());
break;
}
}
osmOutput.complete();
output.close();
Util.iterate(file, true);
Util.iterate(file, false);
file.delete();
}
Aggregations