Ticket #23731: 23731.patch

File 23731.patch, 2.0 KB (added by GerdP, 5 months ago)

This patch reverts the change in OsmDataSessionExporter.exportData() from r19002 and adds a comment that the stream should not be closed.

  • src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io.session;
    33
    4 import java.io.IOException;
    54import java.io.OutputStream;
    65import java.io.OutputStreamWriter;
    76import java.io.PrintWriter;
    8 import java.io.UncheckedIOException;
    97import java.io.Writer;
    108import java.nio.charset.StandardCharsets;
    119
     
    1311import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1412import org.openstreetmap.josm.io.OsmWriter;
    1513import org.openstreetmap.josm.io.OsmWriterFactory;
    16 import org.openstreetmap.josm.tools.JosmRuntimeException;
    1714
    1815/**
    1916 * Session exporter for {@link OsmDataLayer}.
     
    3734    /**
    3835     * Exports OSM data to the given output stream.
    3936     * @param data data set
    40      * @param out output stream
     37     * @param out output stream (must not be closed)
    4138     * @since 15386
    4239     */
    4340    public static void exportData(DataSet data, OutputStream out) {
    4441        Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
     42        OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion());
    4543        data.getReadLock().lock();
    46         try (OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion())) {
     44        try {
    4745            w.write(data);
    4846            w.flush();
    49         } catch (IOException e) {
    50             // Catch needed since XmlWriter (parent of OsmWriter) has IOException in the method signature.
    51             // It doesn't actually throw though. In other words, we should never hit this.
    52             throw new UncheckedIOException(e);
    5347        } finally {
    5448            data.getReadLock().unlock();
    5549        }