Changeset 7870 in josm for trunk/src


Ignore:
Timestamp:
2014-12-21T16:23:21+01:00 (5 years ago)
Author:
Don-vip
Message:

cleanup of NoteImporter

File:
1 edited

Legend:

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

    r7608 r7870  
    55
    66import java.io.File;
    7 import java.io.FileInputStream;
    87import java.io.IOException;
    98import java.io.InputStream;
     
    1615import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1716import org.openstreetmap.josm.gui.util.GuiHelper;
    18 import org.openstreetmap.josm.tools.Utils;
    1917import org.xml.sax.SAXException;
    2018
    2119/**
    2220 * File importer that reads note dump files (*.osn and .osn.bz2)
     21 * @since 7538
    2322 */
    2423public class NoteImporter extends FileImporter {
     
    3332
    3433    @Override
    35     public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
    36         Main.debug("importing notes file " + file.getAbsolutePath());
    37         final String fileName = file.getName();
    38         InputStream is;
    39         if(fileName.endsWith(".bz2")) {
    40             is = Utils.getBZip2InputStream(new FileInputStream(file));
    41         } else {
    42             is = new FileInputStream(file);
     34    public void importData(final File file, ProgressMonitor progressMonitor) throws IOException {
     35        if (Main.isDebugEnabled()) {
     36            Main.debug("importing notes file " + file.getAbsolutePath());
    4337        }
    44         NoteReader reader = new NoteReader(is);
    45         try {
    46             final List<Note> fileNotes = reader.parse();
     38        try (InputStream is = Compression.getUncompressedFileInputStream(file)) {
     39            final List<Note> fileNotes = new NoteReader(is).parse();
    4740
    4841            List<NoteLayer> noteLayers = null;
     
    5043                noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class);
    5144            }
    52             if (noteLayers != null && noteLayers.size() > 0) {
    53                 NoteLayer layer = noteLayers.get(0);
    54                 layer.getNoteData().addNotes(fileNotes);
     45            if (noteLayers != null && !noteLayers.isEmpty()) {
     46                noteLayers.get(0).getNoteData().addNotes(fileNotes);
    5547            } else {
    5648                GuiHelper.runInEDT(new Runnable() {
    5749                    @Override
    5850                    public void run() {
    59                         NoteLayer layer = new NoteLayer(fileNotes, fileName);
    60                         Main.main.addLayer(layer);
     51                        Main.main.addLayer(new NoteLayer(fileNotes, file.getName()));
    6152                    }
    6253                });
     
    6758            throw new IOException(e.getMessage(), e);
    6859        }
    69         finally {
    70             Utils.close(is);
    71         }
    7260    }
    73 
    7461}
Note: See TracChangeset for help on using the changeset viewer.