Index: /trunk/src/org/openstreetmap/josm/io/GpxImporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 3371)
+++ /trunk/src/org/openstreetmap/josm/io/GpxImporter.java	(revision 3372)
@@ -37,14 +37,4 @@
                 is = new FileInputStream(file);
             }
-            // Workaround for SAX BOM bug
-            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206835
-            if (!((is.read() == 0xef) && (is.read() == 0xbb) && (is.read() == 0xbf))) {
-                is.close();
-                if (file.getName().endsWith(".gpx.gz")) {
-                    is = new GZIPInputStream(new FileInputStream(file));
-                } else {
-                    is = new FileInputStream(file);
-                }
-            }
             final GpxReader r = new GpxReader(is);
             final boolean parsedProperly = r.parse(true);
Index: /trunk/src/org/openstreetmap/josm/io/GpxReader.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/GpxReader.java	(revision 3371)
+++ /trunk/src/org/openstreetmap/josm/io/GpxReader.java	(revision 3372)
@@ -355,5 +355,5 @@
      */
     public GpxReader(InputStream source) throws IOException {
-        this.inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));
+        this.inputSource = new InputSource(UTFInputStreamReader.create(source, "UTF-8"));
     }
 
Index: /trunk/src/org/openstreetmap/josm/io/OsmReader.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/OsmReader.java	(revision 3371)
+++ /trunk/src/org/openstreetmap/josm/io/OsmReader.java	(revision 3372)
@@ -1,2 +1,3 @@
+// License: GPL. See LICENSE file for details.
 package org.openstreetmap.josm.io;
 
@@ -4,5 +5,4 @@
 
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -570,5 +570,6 @@
             progressMonitor.beginTask(tr("Prepare OSM data...", 2));
             progressMonitor.indeterminateSubTask(tr("Parsing OSM data..."));
-            InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));
+
+            InputSource inputSource = new InputSource(UTFInputStreamReader.create(source, "UTF-8"));
             SAXParserFactory.newInstance().newSAXParser().parse(inputSource, reader.new Parser());
             progressMonitor.worked(1);
Index: /trunk/src/org/openstreetmap/josm/io/UTFInputStreamReader.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/UTFInputStreamReader.java	(revision 3372)
+++ /trunk/src/org/openstreetmap/josm/io/UTFInputStreamReader.java	(revision 3372)
@@ -0,0 +1,64 @@
+// License: GPL. See LICENSE file for details.
+package org.openstreetmap.josm.io;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PushbackInputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Detects the different UTF encodings from byte order mark
+ */
+public class UTFInputStreamReader extends InputStreamReader {
+    /**
+     * converts input stream to reader
+     * @param defaultEncoding Used, when no BOM was recognized. Can be null.
+     * @return A reader with the correct encoding. Starts to read after the BOM.
+     */
+    public static UTFInputStreamReader create(InputStream input, String defaultEncoding) throws IOException {
+        byte bom[] = new byte[4];
+        String encoding = defaultEncoding;
+        int unread;
+        PushbackInputStream pushbackStream = new PushbackInputStream(input, 4);
+        int n = pushbackStream.read(bom, 0, 4);
+
+        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
+            encoding = "UTF-8";
+            unread = n - 3;
+        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
+            encoding = "UTF-32BE";
+            unread = n - 4;
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
+            encoding = "UTF-32LE";
+            unread = n - 4;
+        } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
+            encoding = "UTF-16BE";
+            unread = n - 2;
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
+            encoding = "UTF-16LE";
+            unread = n - 2;
+        } else {
+            unread = n;
+        }
+
+        if (unread > 0) {
+            pushbackStream.unread(bom, (n - unread), unread);
+        } else if (unread < -1) {
+            pushbackStream.unread(bom, 0, 0);
+        }
+
+        if (encoding == null) {
+            return new UTFInputStreamReader(pushbackStream);
+        } else {
+            return new UTFInputStreamReader(pushbackStream, encoding);
+        }
+    }
+
+    private UTFInputStreamReader(InputStream in) {
+        super(in);
+    }
+    private UTFInputStreamReader(InputStream in, String cs) throws UnsupportedEncodingException {
+        super(in, cs);
+    }
+}
