Ticket #23731: 23731.patch
File 23731.patch, 2.0 KB (added by , 5 months ago) |
---|
-
src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.io.session; 3 3 4 import java.io.IOException;5 4 import java.io.OutputStream; 6 5 import java.io.OutputStreamWriter; 7 6 import java.io.PrintWriter; 8 import java.io.UncheckedIOException;9 7 import java.io.Writer; 10 8 import java.nio.charset.StandardCharsets; 11 9 … … 13 11 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 12 import org.openstreetmap.josm.io.OsmWriter; 15 13 import org.openstreetmap.josm.io.OsmWriterFactory; 16 import org.openstreetmap.josm.tools.JosmRuntimeException;17 14 18 15 /** 19 16 * Session exporter for {@link OsmDataLayer}. … … 37 34 /** 38 35 * Exports OSM data to the given output stream. 39 36 * @param data data set 40 * @param out output stream 37 * @param out output stream (must not be closed) 41 38 * @since 15386 42 39 */ 43 40 public static void exportData(DataSet data, OutputStream out) { 44 41 Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); 42 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion()); 45 43 data.getReadLock().lock(); 46 try (OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion())){44 try { 47 45 w.write(data); 48 46 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);53 47 } finally { 54 48 data.getReadLock().unlock(); 55 49 }