Class OsmWriter

java.lang.Object
org.openstreetmap.josm.io.XmlWriter
org.openstreetmap.josm.io.OsmWriter
All Implemented Interfaces:
Closeable, AutoCloseable, PrimitiveVisitor

public class OsmWriter extends XmlWriter implements PrimitiveVisitor
Save the dataset into a stream as osm intern xml format. This is not using any xml library for storing.
Since:
59
  • Field Details

  • Constructor Details

    • OsmWriter

      protected OsmWriter(PrintWriter out, boolean osmConform, String version)
      Constructs a new OsmWriter. Do not call this directly. Use OsmWriterFactory instead.
      Parameters:
      out - print writer
      osmConform - if true, prevents modification attributes to be written to the common part
      version - OSM API version (0.6)
  • Method Details

    • setWithBody

      public void setWithBody(boolean wb)
      Sets whether body must be written.
      Parameters:
      wb - if true body will be written.
    • setWithVisible

      public void setWithVisible(boolean wv)
      Sets whether 'visible' attribute must be written.
      Parameters:
      wv - if true 'visible' attribute will be written.
      Since:
      12019
    • setIsOsmChange

      public void setIsOsmChange(boolean isOsmChange)
    • setChangeset

      public void setChangeset(Changeset cs)
    • setVersion

      public void setVersion(String v)
    • header

      public void header()
      Writes OSM header with normal download and upload policies.
    • header

      public void header(DownloadPolicy download, UploadPolicy upload)
      Writes OSM header with given download upload policies.
      Parameters:
      download - download policy
      upload - upload policy
      Since:
      13485
    • header

      private void header(DownloadPolicy download, UploadPolicy upload, boolean locked)
    • footer

      public void footer()
      Writes OSM footer.
    • sortById

      protected <T extends OsmPrimitive> Collection<T> sortById(Collection<T> primitives)
    • write

      public void write(DataSet data)
      Writes the full OSM file for the given data set (header, data sources, osm data, footer).
      Parameters:
      data - OSM data set
      Since:
      12800
    • writeContent

      public void writeContent(DataSet ds)
      Writes the contents of the given dataset (nodes, then ways, then relations)
      Parameters:
      ds - The dataset to write
    • writeNodes

      public void writeNodes(Collection<Node> nodes)
      Writes the given nodes sorted by id
      Parameters:
      nodes - The nodes to write
      Since:
      5737
    • writeWays

      public void writeWays(Collection<Way> ways)
      Writes the given ways sorted by id
      Parameters:
      ways - The ways to write
      Since:
      5737
    • writeRelations

      public void writeRelations(Collection<Relation> relations)
      Writes the given relations sorted by id
      Parameters:
      relations - The relations to write
      Since:
      5737
    • shouldWrite

      protected boolean shouldWrite(OsmPrimitive osm)
    • writeDataSources

      public void writeDataSources(DataSet ds)
      Writes data sources with their respective bounds.
      Parameters:
      ds - data set
    • writeLatLon

      void writeLatLon(LatLon ll)
    • visit

      public void visit(INode n)
      Description copied from interface: PrimitiveVisitor
      Visiting call for nodes.
      Specified by:
      visit in interface PrimitiveVisitor
      Parameters:
      n - The node to inspect.
    • visit

      public void visit(IWay<?> w)
      Description copied from interface: PrimitiveVisitor
      Visiting call for ways.
      Specified by:
      visit in interface PrimitiveVisitor
      Parameters:
      w - The way to inspect.
    • visit

      public void visit(IRelation<?> e)
      Description copied from interface: PrimitiveVisitor
      Visiting call for relations.
      Specified by:
      visit in interface PrimitiveVisitor
      Parameters:
      e - The relation to inspect.
    • visit

      public void visit(Changeset cs)
      Visiting call for changesets.
      Parameters:
      cs - changeset
    • addTags

      protected void addTags(Tagged osm, String tagname, boolean tagOpen)
    • addCommon

      protected void addCommon(IPrimitive osm, String tagname)
      Add the common part as the form of the tag as well as the XML attributes id, action, user, and visible.
      Parameters:
      osm - osm primitive
      tagname - XML tag matching osm primitive (node, way, relation)