Index: /trunk/src/org/openstreetmap/josm/io/Compression.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/Compression.java	(revision 6716)
+++ /trunk/src/org/openstreetmap/josm/io/Compression.java	(revision 6716)
@@ -0,0 +1,106 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io;
+
+import org.apache.tools.bzip2.CBZip2OutputStream;
+import org.openstreetmap.josm.tools.Utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * An enum representing the compression type of a resource.
+ */
+public enum Compression {
+    /**
+     * no compression
+     */
+    NONE,
+    /**
+     * bzip2 compression
+     */
+    BZIP2,
+    /**
+     * gzip compression
+     */
+    GZIP;
+
+    /**
+     * Determines the compression type depending on the suffix of {@code name}.
+     */
+    public static Compression byExtension(String name) {
+        return name != null && name.endsWith(".gz")
+                ? GZIP
+                : name != null && (name.endsWith(".bz2") || name.endsWith(".bz"))
+                ? BZIP2
+                : NONE;
+    }
+
+    /**
+     * Returns an un-compressing {@link InputStream} for {@code in}.
+     *
+     * @throws IOException
+     */
+    public InputStream getUncompressedInputStream(InputStream in) throws IOException {
+        switch (this) {
+            case BZIP2:
+                return FileImporter.getBZip2InputStream(in);
+            case GZIP:
+                return FileImporter.getGZipInputStream(in);
+            case NONE:
+            default:
+                return in;
+        }
+    }
+
+    /**
+     * Returns an un-compressing {@link InputStream} for the {@link File} {@code file}.
+     *
+     * @throws IOException
+     */
+    public static InputStream getUncompressedFileInputStream(File file) throws IOException {
+        return byExtension(file.getName()).getUncompressedInputStream(new FileInputStream(file));
+    }
+
+    /**
+     * Returns an un-compressing {@link InputStream} for the {@link URL} {@code url}.
+     *
+     * @throws IOException
+     */
+    public static InputStream getUncompressedURLInputStream(URL url) throws IOException {
+        return Utils.openURLAndDecompress(url, true);
+    }
+
+    /**
+     * Returns a compressing {@link OutputStream} for {@code out}.
+     *
+     * @throws IOException
+     */
+    public OutputStream getCompressedOutputStream(OutputStream out) throws IOException {
+        switch (this) {
+            case BZIP2:
+                out.write('B');
+                out.write('Z');
+                return new CBZip2OutputStream(out);
+            case GZIP:
+                return new GZIPOutputStream(out);
+            case NONE:
+            default:
+                return out;
+        }
+    }
+
+    /**
+     * Returns a compressing {@link OutputStream} for the {@link File} {@code file}.
+     *
+     * @throws IOException
+     */
+    public static OutputStream getCompressedFileOutputStream(File file) throws IOException {
+        return byExtension(file.getName()).getCompressedOutputStream(new FileOutputStream(file));
+    }
+}
Index: /trunk/src/org/openstreetmap/josm/io/GpxExporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/GpxExporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/GpxExporter.java	(revision 6716)
@@ -10,6 +10,6 @@
 import java.awt.event.KeyEvent;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.text.MessageFormat;
 import java.util.Calendar;
@@ -173,7 +173,7 @@
         }
 
-        FileOutputStream fo = null;
+        OutputStream fo = null;
         try {
-            fo = new FileOutputStream(file);
+            fo = Compression.getCompressedFileOutputStream(file);
             new GpxWriter(fo).write(gpxData);
             fo.flush();
Index: /trunk/src/org/openstreetmap/josm/io/GpxImporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 6716)
@@ -5,8 +5,6 @@
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.zip.GZIPInputStream;
 
 import javax.swing.JOptionPane;
@@ -31,5 +29,5 @@
      */
     public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
-            "gpx,gpx.gz", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz)");
+            "gpx,gpx.gz,gpx.bz2", "gpx", tr("GPX Files") + " (*.gpx *.gpx.gz, *.gpx.bz2)");
 
     /**
@@ -78,11 +76,6 @@
     @Override
     public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
-        InputStream is;
-        if (file.getName().endsWith(".gpx.gz")) {
-            is = new GZIPInputStream(new FileInputStream(file));
-        } else {
-            is = new FileInputStream(file);
-        }
-        String fileName = file.getName();
+        final InputStream is = Compression.getUncompressedFileInputStream(file);
+        final String fileName = file.getName();
 
         try {
Index: /trunk/src/org/openstreetmap/josm/io/OsmBzip2Exporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmBzip2Exporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmBzip2Exporter.java	(revision 6716)
@@ -1,13 +1,4 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.io;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.apache.tools.bzip2.CBZip2OutputStream;
-import org.openstreetmap.josm.tools.Utils;
 
 public class OsmBzip2Exporter extends OsmExporter {
@@ -20,15 +11,5 @@
     }
 
-    @Override
-    protected OutputStream getOutputStream(File file) throws FileNotFoundException, IOException {
-        OutputStream out = new FileOutputStream(file);
-        try {
-            out.write('B');
-            out.write('Z');
-            return new CBZip2OutputStream(out);
-        } catch (IOException e) {
-            Utils.close(out);
-            throw e;
-        }
-    }
+    // compression handling is preformed in super-class
+
 }
Index: /trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java	(revision 6716)
@@ -4,10 +4,5 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
 import org.openstreetmap.josm.actions.ExtensionFileFilter;
-import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 
 public class OsmBzip2Importer extends OsmImporter {
@@ -20,7 +15,5 @@
     }
 
-    @Override
-    public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
-        importData(getBZip2InputStream(new FileInputStream(file)), file, progressMonitor);
-    }
+    // compression handling is preformed in super-class
+
 }
Index: /trunk/src/org/openstreetmap/josm/io/OsmChangeImporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmChangeImporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmChangeImporter.java	(revision 6716)
@@ -5,5 +5,4 @@
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -38,14 +37,5 @@
     @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
         try {
-            FileInputStream in = new FileInputStream(file);
-
-            if (file.getName().endsWith(".osc")) {
-                importData(in, file, progressMonitor);
-            } else if (file.getName().endsWith(".gz")) {
-                importData(getGZipInputStream(in), file, progressMonitor);
-            } else {
-                importData(getBZip2InputStream(in), file, progressMonitor);
-            }
-
+            importData(Compression.getUncompressedFileInputStream(file), file, progressMonitor);
         } catch (FileNotFoundException e) {
             Main.error(e);
Index: /trunk/src/org/openstreetmap/josm/io/OsmExporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmExporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmExporter.java	(revision 6716)
@@ -53,5 +53,5 @@
 
     protected OutputStream getOutputStream(File file) throws FileNotFoundException, IOException {
-        return new FileOutputStream(file);
+        return Compression.getCompressedFileOutputStream(file);
     }
 
Index: /trunk/src/org/openstreetmap/josm/io/OsmGzipExporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmGzipExporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmGzipExporter.java	(revision 6716)
@@ -2,10 +2,4 @@
 package org.openstreetmap.josm.io;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.zip.GZIPOutputStream;
 public class OsmGzipExporter extends OsmExporter {
 
@@ -14,8 +8,5 @@
     }
 
-    @Override
-    protected OutputStream getOutputStream(File file) throws FileNotFoundException, IOException {
-        OutputStream out = new FileOutputStream(file);
-        return new GZIPOutputStream(out);
-    }
+    // compression handling is preformed in super-class
+
 }
Index: /trunk/src/org/openstreetmap/josm/io/OsmGzipImporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmGzipImporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmGzipImporter.java	(revision 6716)
@@ -4,10 +4,5 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
 import org.openstreetmap.josm.actions.ExtensionFileFilter;
-import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 
 public class OsmGzipImporter extends OsmImporter {
@@ -20,7 +15,5 @@
     }
 
-    @Override
-    public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
-        importData(getGZipInputStream(new FileInputStream(file)), file, progressMonitor);
-    }
+    // compression handling is preformed in super-class
+
 }
Index: /trunk/src/org/openstreetmap/josm/io/OsmImporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmImporter.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmImporter.java	(revision 6716)
@@ -5,5 +5,4 @@
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -60,7 +59,7 @@
     @Override
     public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
-        FileInputStream in = null;
+        InputStream in = null;
         try {
-            in = new FileInputStream(file);
+            in = Compression.getUncompressedFileInputStream(file);
             importData(in, file, progressMonitor);
         } catch (FileNotFoundException e) {
Index: /trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java	(revision 6716)
@@ -38,13 +38,4 @@
             this.progressMonitor = progressMonitor;
             this.compression = compression;
-        }
-        
-        protected final InputStream getUncompressedInputStream() throws IOException {
-            switch (compression) {
-                case BZIP2: return FileImporter.getBZip2InputStream(in);
-                case GZIP: return FileImporter.getGZipInputStream(in);
-                case NONE: 
-                default: return in;
-            }
         }
         
@@ -121,5 +112,5 @@
                 return null;
             progressMonitor.subTask(tr("Downloading OSM data..."));
-            return OsmReader.parseDataSet(getUncompressedInputStream(), progressMonitor.createSubTaskMonitor(1, false));
+            return OsmReader.parseDataSet(compression.getUncompressedInputStream(in), progressMonitor.createSubTaskMonitor(1, false));
         }
     }
@@ -136,5 +127,5 @@
                 return null;
             progressMonitor.subTask(tr("Downloading OSM data..."));
-            return OsmChangeReader.parseDataSet(getUncompressedInputStream(), progressMonitor.createSubTaskMonitor(1, false));
+            return OsmChangeReader.parseDataSet(compression.getUncompressedInputStream(in), progressMonitor.createSubTaskMonitor(1, false));
         }
     }
@@ -151,5 +142,5 @@
                 return null;
             progressMonitor.subTask(tr("Downloading OSM data..."));
-            GpxReader reader = new GpxReader(getUncompressedInputStream());
+            GpxReader reader = new GpxReader(compression.getUncompressedInputStream(in));
             gpxParsedProperly = reader.parse(false);
             GpxData result = reader.getGpxData();
Index: /trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmServerReader.java	(revision 6715)
+++ /trunk/src/org/openstreetmap/josm/io/OsmServerReader.java	(revision 6716)
@@ -34,10 +34,4 @@
     private boolean doAuthenticate = false;
     protected boolean gpxParsedProperly;
-    
-    protected enum Compression {
-        NONE,
-        BZIP2,
-        GZIP
-    }
 
     /**
