Ignore:
Timestamp:
2013-04-16T19:57:43+02:00 (11 years ago)
Author:
Don-vip
Message:

see #8570, #7406 - I/O refactorization:

  • Move different file copy functions to Utils.copyFile (to be replaced later by Files.copy when switching to Java 7)
  • Replace all Utils.close(XXX) by Utils.close(Closeable) -> impacted plugins: commandline, mirrored_download, opendata, piclayer
  • Add new Utils.close(ZipFile)
  • Use of Utils.close almost everywhere
  • Javadoc fixes
File:
1 edited

Legend:

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

    r5361 r5874  
    2121import org.openstreetmap.josm.gui.layer.Layer;
    2222import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     23import org.openstreetmap.josm.tools.Utils;
    2324
    2425public class OsmExporter extends FileExporter {
     
    6465            if (file.exists()) {
    6566                tmpFile = new File(file.getPath() + "~");
    66                 copy(file, tmpFile);
     67                Utils.copyFile(file, tmpFile);
    6768            }
    6869
     
    7576            try {
    7677                w.writeLayer(layer);
    77                 w.close();
    7878            } finally {
     79                Utils.close(w);
    7980                layer.data.getReadLock().unlock();
    8081            }
     
    99100                // be deleted.  So, restore the backup if we made one.
    100101                if (tmpFile != null && tmpFile.exists()) {
    101                     copy(tmpFile, file);
     102                    Utils.copyFile(tmpFile, file);
    102103                }
    103104            } catch (IOException e2) {
     
    112113        }
    113114    }
    114 
    115     private void copy(File src, File dst) throws IOException {
    116         FileInputStream srcStream;
    117         FileOutputStream dstStream;
    118         try {
    119             srcStream = new FileInputStream(src);
    120             dstStream = new FileOutputStream(dst);
    121         } catch (FileNotFoundException e) {
    122             JOptionPane.showMessageDialog(Main.parent, tr("Could not back up file. Exception is: {0}", e
    123                     .getMessage()), tr("Error"), JOptionPane.ERROR_MESSAGE);
    124             return;
    125         }
    126         byte buf[] = new byte[1 << 16];
    127         int len;
    128         while ((len = srcStream.read(buf)) != -1) {
    129             dstStream.write(buf, 0, len);
    130         }
    131         srcStream.close();
    132         dstStream.close();
    133     }
    134 
    135115}
Note: See TracChangeset for help on using the changeset viewer.