Changeset 8894 in josm


Ignore:
Timestamp:
2015-10-18T12:48:44+02:00 (9 years ago)
Author:
simon04
Message:

fix #7058 - Ability to load gz and bz2 zipped NMEA files

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r8813 r8894  
    55import java.util.ArrayList;
    66import java.util.Arrays;
     7import java.util.Collection;
    78import java.util.Collections;
    89import java.util.Comparator;
     10import java.util.LinkedHashSet;
    911import java.util.LinkedList;
    1012import java.util.List;
     
    279281
    280282    /**
     283     * Construct an extension file filter with the extensions supported by {@link org.openstreetmap.josm.io.Compression}
     284     * automatically added to the {@code extensions}. The specified {@code extensions} will be added to the description
     285     * in the form {@code old-description (*.ext1, *.ext2)}.
     286     * @param extensions The comma-separated list of file extensions
     287     * @param defaultExtension The default extension
     288     * @param description A short textual description of the file type without supported extensions in parentheses
     289     * @return The constructed filter
     290     */
     291    public static ExtensionFileFilter newFilterWithArchiveExtensions(String extensions, String defaultExtension, String description) {
     292        final Collection<String> extensionsPlusArchive = new LinkedHashSet<>();
     293        final Collection<String> extensionsForDescription = new LinkedHashSet<>();
     294        for (String e : extensions.split(",")) {
     295            extensionsPlusArchive.add(e);
     296            extensionsPlusArchive.add(e + ".gz");
     297            extensionsPlusArchive.add(e + ".bz2");
     298            extensionsForDescription.add("*." + e);
     299            // intentionally do not add [e].gz and [e].bz2 to extensionsForDescription in order to avoid long texts
     300        }
     301        return new ExtensionFileFilter(Utils.join(",", extensionsPlusArchive), defaultExtension,
     302                description + " (" + Utils.join(", ", extensionsForDescription) + ")");
     303    }
     304
     305    /**
    281306     * Returns true if this file filter accepts the given filename.
    282307     * @param filename The filename to check after
  • trunk/src/org/openstreetmap/josm/io/NMEAImporter.java

    r8390 r8894  
    55
    66import java.io.File;
    7 import java.io.FileInputStream;
    87import java.io.IOException;
    98import java.io.InputStream;
     
    3130     * The NMEA file filter (*.nmea *.nme *.nma *.log *.txt files).
    3231     */
    33     public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
    34             "nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files") + " (*.nmea *.nme *.nma *.log *.txt)");
     32    public static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions(
     33            "nmea,nme,nma,log,txt", "nmea", tr("NMEA-0183 Files"));
    3534
    3635    /**
     
    4443    public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
    4544        final String fn = file.getName();
    46         try (InputStream fis = new FileInputStream(file)) {
     45        try (InputStream fis = Compression.getUncompressedFileInputStream(file)) {
    4746            final NmeaReader r = new NmeaReader(fis);
    4847            if (r.getNumberOfCoordinates() > 0) {
Note: See TracChangeset for help on using the changeset viewer.