Search in sources :

Example 1 with OsmOutputStream

use of de.topobyte.osm4j.core.access.OsmOutputStream 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();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) OsmOutputStream(de.topobyte.osm4j.core.access.OsmOutputStream) FileOutputStream(java.io.FileOutputStream) PbfWriter(de.topobyte.osm4j.pbf.seq.PbfWriter) EntityContainer(de.topobyte.osm4j.core.model.iface.EntityContainer) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator) File(java.io.File) OsmOutputStream(de.topobyte.osm4j.core.access.OsmOutputStream)

Aggregations

OsmIterator (de.topobyte.osm4j.core.access.OsmIterator)1 OsmOutputStream (de.topobyte.osm4j.core.access.OsmOutputStream)1 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)1 PbfIterator (de.topobyte.osm4j.pbf.seq.PbfIterator)1 PbfWriter (de.topobyte.osm4j.pbf.seq.PbfWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1