Changeset 6882 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2014-02-25T00:21:39+01:00 (10 years ago)
Author:
Don-vip
Message:

enable loading of .osm.zip files

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
6 edited

Legend:

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

    r6380 r6882  
    4848                "org.openstreetmap.josm.io.OsmImporter",
    4949                "org.openstreetmap.josm.io.OsmGzipImporter",
     50                "org.openstreetmap.josm.io.OsmZipImporter",
    5051                "org.openstreetmap.josm.io.OsmChangeImporter",
    5152                "org.openstreetmap.josm.io.GpxImporter",
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java

    r6798 r6882  
    1919public class DownloadOsmCompressedTask extends DownloadOsmTask {
    2020
    21     static final String PATTERN_GZ =  "https?://.*/.*\\.osm.(gz|bz2?)";
     21    static final String PATTERN_COMPRESS =  "https?://.*/.*\\.osm.(gz|bz2?|zip)";
    2222
    2323    @Override
    2424    public String[] getPatterns() {
    25         return new String[]{PATTERN_GZ};
     25        return new String[]{PATTERN_COMPRESS};
    2626    }
    2727
     
    3131    }
    3232   
    33     /* (non-Javadoc)
    34      * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)
    35      */
    3633    @Override
    3734    public Future<?> download(boolean newLayer, Bounds downloadArea,
     
    5451                if (url.matches("https?://.*/.*\\.osm.bz2?")) {
    5552                    return reader.parseOsmBzip2(subTaskMonitor);
     53                } else if (url.matches("https?://.*/.*\\.osm.gz")) {
     54                    return reader.parseOsmGzip(subTaskMonitor);
    5655                } else {
    57                     return reader.parseOsmGzip(subTaskMonitor);
     56                    return reader.parseOsmZip(subTaskMonitor);
    5857                }
    5958            }
    6059        };
    6160        currentBounds = null;
    62         // Extract .osm.gz/bz/bz2 filename from URL to set the new layer name
    63         extractOsmFilename("https?://.*/(.*\\.osm.(gz|bz2?))", url);
     61        // Extract .osm.gz/bz/bz2/zip filename from URL to set the new layer name
     62        extractOsmFilename("https?://.*/(.*\\.osm.(gz|bz2?|zip))", url);
    6463        return Main.worker.submit(downloadTask);
    6564    }
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r6716 r6882  
    1313import java.net.URL;
    1414import java.util.zip.GZIPOutputStream;
     15import java.util.zip.ZipOutputStream;
    1516
    1617/**
     
    2930     * gzip compression
    3031     */
    31     GZIP;
     32    GZIP,
     33    /**
     34     * zip compression
     35     */
     36    ZIP;
    3237
    3338    /**
    3439     * Determines the compression type depending on the suffix of {@code name}.
     40     * @param name File name including extension
     41     * @return the compression type
    3542     */
    3643    public static Compression byExtension(String name) {
     
    3946                : name != null && (name.endsWith(".bz2") || name.endsWith(".bz"))
    4047                ? BZIP2
     48                : name != null && name.endsWith(".zip")
     49                ? ZIP
    4150                : NONE;
    4251    }
     
    5362            case GZIP:
    5463                return FileImporter.getGZipInputStream(in);
     64            case ZIP:
     65                return FileImporter.getZipInputStream(in);
    5566            case NONE:
    5667            default:
     
    90101            case GZIP:
    91102                return new GZIPOutputStream(out);
     103            case ZIP:
     104                return new ZipOutputStream(out);
    92105            case NONE:
    93106            default:
  • trunk/src/org/openstreetmap/josm/io/FileImporter.java

    r6830 r6882  
    1010import java.util.List;
    1111import java.util.zip.GZIPInputStream;
     12import java.util.zip.ZipEntry;
     13import java.util.zip.ZipInputStream;
    1214
    1315import javax.swing.JOptionPane;
     
    156158    }
    157159
     160    public static ZipInputStream getZipInputStream(InputStream in) throws IOException {
     161        if (in == null) {
     162            return null;
     163        }
     164        ZipInputStream zis = new ZipInputStream(in);
     165        // Positions the stream at the beginning of first entry
     166        ZipEntry ze = zis.getNextEntry();
     167        if (ze != null && Main.isDebugEnabled()) {
     168            Main.debug("Zip entry: "+ze.getName());
     169        }
     170        return zis;
     171    }
     172
    158173    /**
    159174     * Returns the enabled state of this {@code FileImporter}. When enabled, it is listed and usable in "File-&gt;Open" dialog.
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r6803 r6882  
    7777
    7878    @Override
     79    public DataSet parseOsmZip(final ProgressMonitor progressMonitor) throws OsmTransferException {
     80        return doParse(new OsmParser(progressMonitor, Compression.ZIP), progressMonitor);
     81    }
     82
     83    @Override
    7984    public DataSet parseOsmChange(final ProgressMonitor progressMonitor) throws OsmTransferException {
    8085        return doParse(new OsmChangeParser(progressMonitor, Compression.NONE), progressMonitor);
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r6852 r6882  
    303303
    304304    /**
     305     * Download Zip-compressed OSM files from somewhere
     306     * @param progressMonitor The progress monitor
     307     * @return The corresponding dataset
     308     * @throws OsmTransferException if any error occurs
     309     * @since 6882
     310     */
     311    public DataSet parseOsmZip(final ProgressMonitor progressMonitor) throws OsmTransferException {
     312        return null;
     313    }
     314
     315    /**
    305316     * Returns true if this reader is adding authentication credentials to the read
    306317     * request sent to the server.
Note: See TracChangeset for help on using the changeset viewer.