Changeset 7562 in josm for trunk/src/org


Ignore:
Timestamp:
2014-09-19T01:13:02+02:00 (5 years ago)
Author:
Don-vip
Message:

see #9704 - more code refactorization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r7561 r7562  
    2323
    2424/**
    25  * Exports data to an .Osm file.
     25 * Exports data to an .osm file.
    2626 * @since 1949
    2727 */
     
    6868    }
    6969
    70     protected static final void checkOsmDataLayer(Layer layer) throws IllegalArgumentException {
     70    protected static void checkOsmDataLayer(Layer layer) throws IllegalArgumentException {
    7171        if (!(layer instanceof OsmDataLayer)) {
    7272            throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer. Got ''{0}''.", layer
     
    9090            }
    9191
    92             // create outputstream and wrap it with gzip or bzip, if necessary
    93             try (
    94                 OutputStream out = getOutputStream(file);
    95                 Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
    96                 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion());
    97             ) {
    98                 layer.data.getReadLock().lock();
    99                 try {
    100                     w.writeLayer(layer);
    101                 } finally {
    102                     layer.data.getReadLock().unlock();
    103                 }
    104             }
     92            doSave(file, layer);
    10593            if (noBackup || !Main.pref.getBoolean("save.keepbackup", false)) {
    10694                if (tmpFile != null) {
     
    135123        }
    136124    }
     125
     126    protected void doSave(File file, OsmDataLayer layer) throws IOException, FileNotFoundException {
     127        // create outputstream and wrap it with gzip or bzip, if necessary
     128        try (
     129            OutputStream out = getOutputStream(file);
     130            Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
     131            OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion());
     132        ) {
     133            layer.data.getReadLock().lock();
     134            try {
     135                w.writeLayer(layer);
     136            } finally {
     137                layer.data.getReadLock().unlock();
     138            }
     139        }
     140    }
    137141}
Note: See TracChangeset for help on using the changeset viewer.