Changeset 1653 in josm


Ignore:
Timestamp:
2009-06-07T16:18:31+02:00 (15 years ago)
Author:
stoecker
Message:

add support for compressed OSM files (bzip2, gzip)

Location:
trunk/src/org
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r1637 r1653  
    1111import org.openstreetmap.josm.io.GpxImporter;
    1212import org.openstreetmap.josm.io.NMEAImporter;
     13import org.openstreetmap.josm.io.OsmBzip2Importer;
     14import org.openstreetmap.josm.io.OsmGzipImporter;
    1315import org.openstreetmap.josm.io.OsmImporter;
    1416
     
    2527
    2628    public static ArrayList<FileImporter> importers = new ArrayList<FileImporter>(Arrays.asList(new OsmImporter(),
    27             new GpxImporter(), new NMEAImporter()));
     29            new OsmGzipImporter(), new OsmBzip2Importer(), new GpxImporter(), new NMEAImporter()));
    2830
    2931    /**
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r1646 r1653  
    1010import java.io.FileOutputStream;
    1111import java.io.IOException;
     12import java.io.OutputStream;
     13import java.io.OutputStreamWriter;
    1214import java.io.PrintWriter;
    13 
    14 import javax.swing.JFileChooser;
     15import java.io.Writer;
     16import java.util.zip.GZIPOutputStream;
     17
    1518import javax.swing.JOptionPane;
    1619
     20import org.apache.tools.bzip2.CBZip2OutputStream;
    1721import org.openstreetmap.josm.Main;
    1822import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2327import org.openstreetmap.josm.io.GpxImporter;
    2428import org.openstreetmap.josm.io.GpxWriter;
     29import org.openstreetmap.josm.io.OsmBzip2Importer;
     30import org.openstreetmap.josm.io.OsmGzipImporter;
    2531import org.openstreetmap.josm.io.OsmImporter;
    2632import org.openstreetmap.josm.io.OsmWriter;
     
    140146            GpxImporter gpxImExporter = new GpxImporter();
    141147            OsmImporter osmImExporter = new OsmImporter();
     148            OsmGzipImporter osmGzipImporter = new OsmGzipImporter();
     149            OsmBzip2Importer osmBzip2Importer = new OsmBzip2Importer();
    142150            if (gpxImExporter.acceptFile(file))
    143151                GpxExportAction.exportGpx(file, layer);
    144             else if (osmImExporter.acceptFile(file)) {
     152            else if (osmImExporter.acceptFile(file)
     153                    || osmGzipImporter.acceptFile(file)
     154                    || osmBzip2Importer.acceptFile(file))
     155            {
    145156                // use a tmp file because if something errors out in the
    146157                // process of writing the file, we might just end up with
     
    150161                    copy(file, tmpFile);
    151162                }
    152                 OsmWriter w = new OsmWriter(new PrintWriter(file, "UTF-8"), false, layer.data.version);
     163
     164                // create outputstream and wrap it with gzip or bzip, if necessary
     165                OutputStream out = new FileOutputStream(file);
     166                if(osmGzipImporter.acceptFile(file)) {
     167                    out = new GZIPOutputStream(out);
     168                } else if(osmBzip2Importer.acceptFile(file)) {
     169                    out.write('B');
     170                    out.write('Z');
     171                    out = new CBZip2OutputStream(out);
     172                }
     173                Writer writer = new OutputStreamWriter(out, "UTF-8");
     174
     175                OsmWriter w = new OsmWriter(new PrintWriter(writer), false, layer.data.version);
    153176                w.header();
    154177                w.writeDataSources(layer.data);
  • trunk/src/org/openstreetmap/josm/gui/conflict/ListMerger.java

    r1650 r1653  
    4040/**
    4141 * A UI component for resolving conflicts in two lists of entries of type T.
    42  * 
     42 *
    4343 * @param T  the type of the entries
    4444 * @see ListMergeModel
     
    687687     * Action for removing the selected entries in the list of merged entries
    688688     * from the list of merged entries.
    689      * 
     689     *
    690690     */
    691691    class RemoveMergedAction extends AbstractAction implements ListSelectionListener {
     
    740740         * such that the action gets notified about item state changes and the button gets
    741741         * notified about selection state changes of the action.
    742          * 
     742         *
    743743         * @param btn a toggle button
    744744         */
     
    811811    public void update(Observable o, Object arg) {
    812812        lblMyVersion.setText(
    813                 tr("My version ")
    814                 + trn("({0} entry)", "({0} entries)", model.getMyEntriesSize(), model.getMyEntriesSize())
     813                trn("My version ({0} entry)", "My version ({0} entries)", model.getMyEntriesSize(), model.getMyEntriesSize())
    815814        );
    816815        lblMergedVersion.setText(
    817                 tr("Merged version ")
    818                 + trn("({0} entry)", "({0} entries)", model.getMergedEntriesSize(), model.getMergedEntriesSize())
     816                trn("Merged version ({0} entry)", "Merged version ({0} entries)", model.getMergedEntriesSize(), model.getMergedEntriesSize())
    819817        );
    820818        lblTheirVersion.setText(
    821                 tr("Their version ")
    822                 + trn("({0} entry)", "({0} entries)", model.getTheirEntriesSize(), model.getTheirEntriesSize())
     819                trn("Their version ({0} entry)", "Their version ({0} entries)", model.getTheirEntriesSize(), model.getTheirEntriesSize())
    823820        );
    824821    }
    825 
    826 
    827822
    828823    /**
     
    831826     * the registerd Adjustables is updated the adjustment of
    832827     * the other registered Adjustables is adjusted too.
    833      * 
     828     *
    834829     */
    835830    class AdjustmentSynchronizer implements AdjustmentListener {
     
    850845         * registers an {@see Adjustable} for participation in synchronized
    851846         * scrolling.
    852          * 
     847         *
    853848         * @param adjustable the adjustable
    854849         */
     
    865860        /**
    866861         * event handler for {@see AdjustmentEvent}s
    867          * 
     862         *
    868863         */
    869864        public void adjustmentValueChanged(AdjustmentEvent e) {
     
    880875         * sets whether adjustable participates in adjustment synchronization
    881876         * or not
    882          * 
     877         *
    883878         * @param adjustable the adjustable
    884879         */
     
    896891        /**
    897892         * returns true if an adjustable is participating in synchronized scrolling
    898          * 
     893         *
    899894         * @param adjustable the adjustable
    900895         * @return true, if the adjustable is participating in synchronized scrolling, false otherwise
     
    916911         *      {@see JCheckBox}</ol>
    917912         * </li>
    918          * 
    919          * 
     913         *
     914         *
    920915         * @param view  the checkbox to control whether an adjustable participates in synchronized
    921916         *      adjustment
  • trunk/src/org/openstreetmap/josm/io/OsmImporter.java

    r1637 r1653  
    99import java.io.FileNotFoundException;
    1010import java.io.IOException;
     11import java.io.InputStream;
    1112
    1213import javax.swing.JOptionPane;
     
    2425    }
    2526
     27    public OsmImporter(ExtensionFileFilter filter) {
     28        super(filter);
     29    }
     30
    2631    @Override public void importData(File file) throws IOException {
    2732        try {
    28             OsmReader osm = OsmReader.parseDataSetOsm(new FileInputStream(file), null, Main.pleaseWaitDlg);
    29             DataSet dataSet = osm.getDs();
    30             OsmDataLayer layer = new OsmDataLayer(dataSet, file.getName(), file);
    31             Main.main.addLayer(layer);
    32             layer.fireDataChange();
    33             if (osm.getParseNotes().length() != 0) {
    34                 /* display at most five lines */
    35                 String notes = osm.getParseNotes();
    36                 int j = 0;
    37                 for (int i = 0; i < 5; i++)
    38                     j = notes.indexOf('\n', j + 1);
    39                 j = j >= 0 ? j : notes.length();
    40                 JOptionPane.showMessageDialog(Main.parent, notes.substring(0, j));
    41             }
     33            FileInputStream in = new FileInputStream(file);
     34            importData(in, file);
    4235        } catch (HeadlessException e) {
    4336            e.printStackTrace();
     
    5144        }
    5245    }
     46
     47    protected void importData(InputStream in, File associatedFile) throws SAXException, IOException {
     48        OsmReader osm = OsmReader.parseDataSetOsm(in, null, Main.pleaseWaitDlg);
     49        DataSet dataSet = osm.getDs();
     50        OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile);
     51        Main.main.addLayer(layer);
     52        layer.fireDataChange();
     53        if (osm.getParseNotes().length() != 0) {
     54            /* display at most five lines */
     55            String notes = osm.getParseNotes();
     56            int j = 0;
     57            for (int i = 0; i < 5; i++)
     58                j = notes.indexOf('\n', j + 1);
     59            j = j >= 0 ? j : notes.length();
     60            JOptionPane.showMessageDialog(Main.parent, notes.substring(0, j));
     61        }
     62    }
    5363}
Note: See TracChangeset for help on using the changeset viewer.