Changeset 19104 in josm
- Timestamp:
- 2024-06-13T14:05:00+02:00 (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
r19103 r19104 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; … … 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 /** … … 38 35 * Exports OSM data to the given output stream. 39 36 * @param data data set 40 * @param out output stream 41 * @since 15386 37 * @param out output stream (must be closed by caller; note: if caller has access, caller should use 38 * {@link org.apache.commons.io.output.CloseShieldOutputStream} when calling this method to 39 * avoid potential future issues) 42 40 */ 41 @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) // All the closeables in this method will close the input OutputStream. 43 42 public static void exportData(DataSet data, OutputStream out) { 43 // This writer will close out when it is closed 44 44 Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); 45 // The PrintWriter will close the writer when it is closed, and the OsmWriter will close the PrintWriter when it is closed. 46 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion()); 45 47 data.getReadLock().lock(); 46 try (OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, data.getVersion())){48 try { 47 49 w.write(data); 48 50 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 51 } finally { 54 52 data.getReadLock().unlock();
Note:
See TracChangeset
for help on using the changeset viewer.