Index: trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java	(revision 5874)
@@ -38,4 +38,5 @@
 import org.openstreetmap.josm.tools.MultiMap;
 import org.openstreetmap.josm.tools.Shortcut;
+import org.openstreetmap.josm.tools.Utils;
 import org.xml.sax.SAXException;
 
@@ -48,4 +49,7 @@
 public class OpenFileAction extends DiskAccessAction {
 
+    /**
+     * The {@link ExtensionFileFilter} matching .url files
+     */
     public static final ExtensionFileFilter urlFileFilter = new ExtensionFileFilter("url", "url", tr("URL Files") + " (*.url)");
 
@@ -57,5 +61,4 @@
                 Shortcut.registerShortcut("system:open", tr("File: {0}", tr("Open...")), KeyEvent.VK_O, Shortcut.CTRL));
         putValue("help", ht("/Action/Open"));
-
     }
 
@@ -296,5 +299,5 @@
                             }
                         }
-                        reader.close();
+                        Utils.close(reader);
                     } catch (Exception e) {
                         System.err.println(e.getMessage());
@@ -333,4 +336,8 @@
         }
 
+        /**
+         * Replies the list of files that have been successfully opened.
+         * @return The list of files that have been successfully opened.
+         */
         public List<File> getSuccessfullyOpenedFiles() {
             return successfullyOpenedFiles;
Index: trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/AutosaveTask.java	(revision 5874)
@@ -38,4 +38,5 @@
 import org.openstreetmap.josm.io.OsmExporter;
 import org.openstreetmap.josm.io.OsmImporter;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -156,5 +157,5 @@
                         PrintStream ps = new PrintStream(pidFile);
                         ps.println(ManagementFactory.getRuntimeMXBean().getName());
-                        ps.close();
+                        Utils.close(ps);
                     } catch (Throwable t) {
                         System.err.println(t.getMessage());
@@ -299,5 +300,5 @@
                             System.err.println(t.getClass()+":"+t.getMessage());
                         } finally {
-                            reader.close();
+                            Utils.close(reader);
                         }
                     } catch (Throwable t) {
Index: trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java	(revision 5874)
@@ -1,7 +1,4 @@
 package org.openstreetmap.josm.data;
 
-import javax.script.ScriptException;
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.Preferences.Setting;
 import static org.openstreetmap.josm.tools.I18n.tr;
 
@@ -12,9 +9,6 @@
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.InputStream;
-
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,6 +24,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
@@ -42,4 +38,6 @@
 import javax.xml.transform.stream.StreamResult;
 
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.Preferences.Setting;
 import org.openstreetmap.josm.gui.io.DownloadFileTask;
 import org.openstreetmap.josm.plugins.PluginDownloadTask;
@@ -47,4 +45,5 @@
 import org.openstreetmap.josm.plugins.ReadLocalPluginInformationTask;
 import org.openstreetmap.josm.tools.LanguageInfo;
+import org.openstreetmap.josm.tools.Utils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -441,9 +440,5 @@
                 log("Error reading custom preferences: "+ex.getMessage());
             } finally {
-                try {
-                    if (is != null) {
-                        is.close();
-                    }
-                } catch (IOException ex) {         }
+                Utils.close(is);
             }
             log("-- Reading complete --");
Index: trunk/src/org/openstreetmap/josm/data/Preferences.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 5874)
@@ -18,5 +18,4 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.reflect.Field;
-import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -137,63 +136,98 @@
     }
 
+    /**
+     * Base abstract class of all settings, holding the setting value.
+     *
+     * @param <T> The setting type
+     */
     abstract public static class AbstractSetting<T> implements Setting<T> {
-        private T value;
+        private final T value;
+        /**
+         * Constructs a new {@code AbstractSetting} with the given value
+         * @param value The setting value
+         */
         public AbstractSetting(T value) {
             this.value = value;
         }
-        @Override
-        public T getValue() {
+        @Override public T getValue() {
             return value;
         }
-        @Override
-        public String toString() {
+        @Override public String toString() {
             return value != null ? value.toString() : "null";
         }
     }
 
+    /**
+     * Setting containing a {@link String} value.
+     */
     public static class StringSetting extends AbstractSetting<String> {
+        /**
+         * Constructs a new {@code StringSetting} with the given value
+         * @param value The setting value
+         */
         public StringSetting(String value) {
             super(value);
         }
-        public void visit(SettingVisitor visitor) {
+        @Override public void visit(SettingVisitor visitor) {
             visitor.visit(this);
         }
-        public StringSetting getNullInstance() {
+        @Override public StringSetting getNullInstance() {
             return new StringSetting(null);
         }
     }
 
+    /**
+     * Setting containing a {@link List} of {@link String} values.
+     */
     public static class ListSetting extends AbstractSetting<List<String>> {
+        /**
+         * Constructs a new {@code ListSetting} with the given value
+         * @param value The setting value
+         */
         public ListSetting(List<String> value) {
             super(value);
         }
-        public void visit(SettingVisitor visitor) {
+        @Override public void visit(SettingVisitor visitor) {
             visitor.visit(this);
         }
-        public ListSetting getNullInstance() {
+        @Override public ListSetting getNullInstance() {
             return new ListSetting(null);
         }
     }
 
+    /**
+     * Setting containing a {@link List} of {@code List}s of {@link String} values.
+     */
     public static class ListListSetting extends AbstractSetting<List<List<String>>> {
+        /**
+         * Constructs a new {@code ListListSetting} with the given value
+         * @param value The setting value
+         */
         public ListListSetting(List<List<String>> value) {
             super(value);
         }
-        public void visit(SettingVisitor visitor) {
+        @Override public void visit(SettingVisitor visitor) {
             visitor.visit(this);
         }
-        public ListListSetting getNullInstance() {
+        @Override public ListListSetting getNullInstance() {
             return new ListListSetting(null);
         }
     }
 
+    /**
+     * Setting containing a {@link List} of {@link Map}s of {@link String} values.
+     */
     public static class MapListSetting extends AbstractSetting<List<Map<String, String>>> {
+        /**
+         * Constructs a new {@code MapListSetting} with the given value
+         * @param value The setting value
+         */
         public MapListSetting(List<Map<String, String>> value) {
             super(value);
         }
-        public void visit(SettingVisitor visitor) {
+        @Override public void visit(SettingVisitor visitor) {
             visitor.visit(this);
         }
-        public MapListSetting getNullInstance() {
+        @Override public MapListSetting getNullInstance() {
             return new MapListSetting(null);
         }
@@ -265,5 +299,6 @@
 
     /**
-     * Return the location of the user defined preferences file
+     * Returns the location of the user defined preferences directory
+     * @return The location of the user defined preferences directory
      */
     public String getPreferencesDir() {
@@ -274,4 +309,8 @@
     }
 
+    /**
+     * Returns the user defined preferences directory
+     * @return The user defined preferences directory
+     */
     public File getPreferencesDirFile() {
         if (preferencesDirFile != null)
@@ -292,8 +331,16 @@
     }
 
+    /**
+     * Returns the user preferences file
+     * @return The user preferences file
+     */
     public File getPreferenceFile() {
         return new File(getPreferencesDirFile(), "preferences.xml");
     }
 
+    /**
+     * Returns the user plugin directory
+     * @return The user plugin directory
+     */
     public File getPluginsDirectory() {
         return new File(getPreferencesDirFile(), "plugins");
@@ -551,6 +598,6 @@
 
         // Backup old preferences if there are old preferences
-        if(prefFile.exists()) {
-            copyFile(prefFile, backupFile);
+        if (prefFile.exists()) {
+            Utils.copyFile(prefFile, backupFile);
         }
 
@@ -558,8 +605,8 @@
                 new FileOutputStream(prefFile + "_tmp"), "utf-8"), false);
         out.print(toXML(false));
-        out.close();
+        Utils.close(out);
 
         File tmpFile = new File(prefFile + "_tmp");
-        copyFile(tmpFile, prefFile);
+        Utils.copyFile(tmpFile, prefFile);
         tmpFile.delete();
 
@@ -575,31 +622,4 @@
         file.setReadable(true, true);
         file.setWritable(true, true);
-    }
-
-    /**
-     * Simple file copy function that will overwrite the target file
-     * Taken from http://www.rgagnon.com/javadetails/java-0064.html (CC-NC-BY-SA)
-     * @param in
-     * @param out
-     * @throws IOException
-     */
-    public static void copyFile(File in, File out) throws IOException  {
-        FileChannel inChannel = new FileInputStream(in).getChannel();
-        FileChannel outChannel = new FileOutputStream(out).getChannel();
-        try {
-            inChannel.transferTo(0, inChannel.size(),
-                    outChannel);
-        }
-        catch (IOException e) {
-            throw e;
-        }
-        finally {
-            if (inChannel != null) {
-                inChannel.close();
-            }
-            if (outChannel != null) {
-                outChannel.close();
-            }
-        }
     }
 
@@ -615,5 +635,5 @@
                 fromXML(in);
             } finally {
-                in.close();
+                Utils.close(in);
             }
         }
Index: trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java	(revision 5874)
@@ -22,4 +22,5 @@
 import org.openstreetmap.josm.io.OsmConnection;
 import org.openstreetmap.josm.tools.Base64;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -91,6 +92,6 @@
                 PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutputStream()));
                 out.println(s);
-                out.close();
-                con.getInputStream().close();
+                Utils.close(out);
+                Utils.close(con.getInputStream());
                 con.disconnect();
                 JOptionPane.showMessageDialog(
Index: trunk/src/org/openstreetmap/josm/data/Version.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/Version.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/Version.java	(revision 5874)
@@ -44,5 +44,5 @@
                 }
             } finally {
-                in.close();
+                Utils.close(in);
             }
             s = sb.toString();
Index: trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WmsCache.java	(revision 5874)
@@ -156,14 +156,6 @@
             }
         } finally {
-            try {
-                if (fis != null) {
-                    fis.close();
-                }
-                if (fos != null) {
-                    fos.close();
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
+            Utils.close(fos);
+            Utils.close(fis);
         }
 
@@ -532,5 +524,5 @@
                 totalFileSize += Utils.copyStream(imageData, os);
             } finally {
-                os.close();
+                Utils.close(os);
             }
         }
Index: trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java	(revision 5874)
@@ -25,4 +25,6 @@
 import java.util.ArrayList;
 import java.util.HashMap;
+
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -151,5 +153,5 @@
         lastSubGrid = topLevelSubGrid[0];
 
-        in.close();
+        Utils.close(in);
     }
 
Index: trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java	(revision 5874)
@@ -57,4 +57,5 @@
 import org.openstreetmap.josm.gui.preferences.ValidatorPreference;
 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -167,12 +168,14 @@
 
     public static void saveIgnoredErrors() {
+        PrintWriter out = null;
         try {
-            final PrintWriter out = new PrintWriter(new FileWriter(getValidatorDir() + "ignorederrors"), false);
+            out = new PrintWriter(new FileWriter(getValidatorDir() + "ignorederrors"), false);
             for (String e : ignoredErrors) {
                 out.println(e);
             }
-            out.close();
-        } catch (final IOException e) {
+        } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+            Utils.close(out);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/BookmarkList.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/BookmarkList.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/BookmarkList.java	(revision 5874)
@@ -32,4 +32,5 @@
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -151,5 +152,5 @@
                         bookmarks.add(b);
                     }
-                    in.close();
+                    Utils.close(in);
                     Collections.sort(bookmarks);
                     for (Bookmark b : bookmarks) {
Index: trunk/src/org/openstreetmap/josm/gui/MultiSplitLayout.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MultiSplitLayout.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/MultiSplitLayout.java	(revision 5874)
@@ -44,4 +44,6 @@
 
 import javax.swing.UIManager;
+
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -1259,5 +1261,5 @@
         }
         finally {
-            try { r.close(); } catch (IOException ignore) {}
+            Utils.close(r);
         }
         return null;
Index: trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java	(revision 5874)
@@ -51,4 +51,5 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.OpenBrowser;
+import org.openstreetmap.josm.tools.Utils;
 import org.openstreetmap.josm.tools.WindowGeometry;
 
@@ -141,9 +142,10 @@
                 css.append("\n");
             }
-            reader.close();
         } catch(Exception e) {
             System.err.println(tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString()));
             e.printStackTrace();
             return ss;
+        } finally {
+            Utils.close(reader);
         }
         ss.addRule(css.toString());
Index: trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java	(revision 5874)
@@ -62,11 +62,5 @@
             throw ex;
         } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch(IOException e) {
-                    // ignore
-                }
-            }
+            Utils.close(in);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java	(revision 5874)
@@ -23,5 +23,4 @@
 import org.xml.sax.SAXException;
 
-
 /**
  * Asynchronous task for downloading and unpacking arbitrary file lists
@@ -38,6 +37,9 @@
      *
      * @param parent the parent component relative to which the {@link PleaseWaitDialog} is displayed
-     * @param title the title to display in the {@link PleaseWaitDialog}
-     * @throws IllegalArgumentException thrown if toUpdate is null
+     * @param address the URL to download
+     * @param file The destination file
+     * @param mkdir {@code true} if the destination directory must be created, {@code false} otherwise
+     * @param unpack {@code true} if zip archives must be unpacked recursively, {@code false} otherwise
+     * @throws IllegalArgumentException if {@code parent} is null
      */
     public DownloadFileTask(Component parent, String address, File file, boolean mkdir, boolean unpack) {
@@ -47,5 +49,4 @@
         this.mkdir = mkdir;
         this.unpack = unpack;
-                
     }    
     
@@ -76,4 +77,8 @@
     protected void finish() {}
 
+    /**
+     * Performs download.
+     * @throws DownloadException if the URL is invalid or if any I/O error occurs.
+     */
     public void download() throws DownloadException {
         OutputStream out = null;
@@ -107,5 +112,5 @@
                 out.write(buffer, 0, read);
                 count+=read;
-                if (canceled) return;                            
+                if (canceled) break;                            
                 p2 = 100 * count / size;
                 if (p2!=p1) {
@@ -114,10 +119,12 @@
                 }
             }
-            out.close();
-            System.out.println(tr("Download finished"));
-            if (unpack) {
-                System.out.println(tr("Unpacking {0} into {1}", file.getAbsolutePath(), file.getParent()));
-                unzipFileRecursively(file, file.getParent());
-                file.delete();
+            Utils.close(out);
+            if (!canceled) {
+                System.out.println(tr("Download finished"));
+                if (unpack) {
+                    System.out.println(tr("Unpacking {0} into {1}", file.getAbsolutePath(), file.getParent()));
+                    unzipFileRecursively(file, file.getParent());
+                    file.delete();
+                }
             }
         } catch(MalformedURLException e) {
@@ -148,5 +155,5 @@
      * Replies true if the task was canceled by the user
      *
-     * @return
+     * @return {@code true} if the task was canceled by the user, {@code false} otherwise
      */
     public boolean isCanceled() {
@@ -182,11 +189,10 @@
                         os.write(buffer, 0, read);
                     }
-                    os.close();
-                    is.close();
-                }
-            }
-            zf.close();
+                    Utils.close(os);
+                    Utils.close(is);
+                }
+            }
         } finally {
-            if (zf!=null) zf.close();
+            Utils.close(zf);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 5874)
@@ -324,5 +324,5 @@
                 UTFInputStreamReader in = UTFInputStreamReader.create(Utils.openURL(u), "utf-8");
                 String r = new Scanner(in).useDelimiter("\\A").next();
-                in.close();
+                Utils.close(in);
                 System.out.println("Successfully loaded Bing attribution data.");
                 return r.getBytes("utf-8");
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 5874)
@@ -31,4 +31,5 @@
 import org.openstreetmap.josm.io.MirroredInputStream;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -247,10 +248,5 @@
             e.printStackTrace();
         } finally {
-            try {
-                if (in != null) {
-                    in.close();
-                }
-            } catch (IOException ex) {
-            }
+            Utils.close(in);
         }
         return null;
Index: trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java	(revision 5874)
@@ -405,5 +405,5 @@
             dout.writeBytes(request);
             dout.flush();
-            dout.close();
+            Utils.close(dout);
 
             // after a successful login the OSM website sends a redirect to a follow up page. Everything
@@ -419,9 +419,5 @@
             throw new OsmLoginFailedException(e);
         } finally {
-            if (dout != null) {
-                try {
-                    dout.close();
-                } catch(IOException e) { /* ignore */ }
-            }
+            Utils.close(dout);
             synchronized(this) {
                 connection = null;
@@ -496,5 +492,4 @@
             dout.writeBytes(request);
             dout.flush();
-            dout.close();
 
             int retCode = connection.getResponseCode();
@@ -506,9 +501,5 @@
             throw new OsmOAuthAuthorizationException(e);
         } finally {
-            if (dout != null) {
-                try {
-                    dout.close();
-                } catch(IOException e) { /* ignore */ }
-            }
+            Utils.close(dout);
             synchronized(this) {
                 connection = null;
Index: trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java	(revision 5874)
@@ -1174,13 +1174,6 @@
         protected void cancel() {
             canceled = true;
-            if (reader!= null) {
-                try {
-                    reader.close();
-                } catch(IOException e) {
-                    // ignore
-                }
-            }
-        }
-
+            Utils.close(reader);
+        }
 
         protected void warn(Exception e) {
Index: trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java	(revision 5874)
@@ -216,9 +216,5 @@
             return;
         } finally {
-            if (bin != null) {
-                try {
-                    bin.close();
-                } catch(IOException e){/* ignore */}
-            }
+            Utils.close(bin);
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java	(revision 5874)
@@ -1590,8 +1590,8 @@
                 tp = TaggingPreset.readAll(new BufferedReader(r), validate);
             } finally {
-                r.close();
+                Utils.close(r);
             }
         } finally {
-            s.close();
+            Utils.close(s);
         }
         return tp;
Index: trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 5874)
@@ -11,4 +11,5 @@
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.tools.Utils;
 import org.xml.sax.SAXException;
 
@@ -52,5 +53,5 @@
                 done = true;
             }
-            in.close();
+            Utils.close(in);
             activeConnection = null;
         }
@@ -145,7 +146,5 @@
         } finally {
             progressMonitor.finishTask();
-            if (in != null) {
-                try {in.close();} catch(IOException e) {}
-            }
+            Utils.close(in);
             activeConnection = null;
         }
Index: trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java	(revision 5874)
@@ -12,4 +12,5 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -159,11 +160,13 @@
             this.data = updateForce();
         else {
+            BufferedInputStream input = null;
             try {
-                BufferedInputStream input = new BufferedInputStream(new FileInputStream(path));
+                input = new BufferedInputStream(new FileInputStream(path));
                 this.data = new byte[input.available()];
                 input.read(this.data);
-                input.close();
             } catch (IOException e) {
                 this.data = updateForce();
+            } finally {
+                Utils.close(input);
             }
         }
@@ -176,11 +179,13 @@
         if (Main.applet)
             return;
+        BufferedOutputStream output = null;
         try {
-            BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(path));
+            output = new BufferedOutputStream(new FileOutputStream(path));
             output.write(this.data);
             output.flush();
-            output.close();
         } catch(Exception e) {
             e.printStackTrace();
+        } finally {
+            Utils.close(output);
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java	(revision 5874)
@@ -14,4 +14,5 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.tools.Utils;
 
 public class GeoJSONExporter extends FileExporter {
@@ -32,5 +33,5 @@
                 out.write(json);
             } finally {
-                out.close();
+                Utils.close(out);
             }
         } else {
Index: trunk/src/org/openstreetmap/josm/io/GpxExporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GpxExporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/GpxExporter.java	(revision 5874)
@@ -36,4 +36,5 @@
 import org.openstreetmap.josm.tools.CheckParameterUtil;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.Utils;
 
 public class GpxExporter extends FileExporter implements GpxConstants {
@@ -169,15 +170,16 @@
         }
 
+        FileOutputStream fo = null;
         try {
-            FileOutputStream fo = new FileOutputStream(file);
+            fo = new FileOutputStream(file);
             new GpxWriter(fo).write(gpxData);
             fo.flush();
-            fo.close();
         } catch (IOException x) {
             x.printStackTrace();
             JOptionPane.showMessageDialog(Main.parent, tr("Error while exporting {0}:\n{1}", fn, x.getMessage()),
                     tr("Error"), JOptionPane.ERROR_MESSAGE);
-        }
-
+        } finally {
+            Utils.close(fo);
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/io/GpxWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/GpxWriter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/GpxWriter.java	(revision 5874)
@@ -38,12 +38,6 @@
     }
 
-    public GpxWriter() {
-        super(null);
-        //sorry for this one here, this will be cleaned up once the new scheme works
-    }
-
     private GpxData data;
     private String indent = "";
-    public String creator = "JOSM GPX export";
 
     private final static int WAY_POINT = 0;
Index: trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java	(revision 5874)
@@ -124,5 +124,5 @@
                 res = zipFile.getInputStream(resentry);
             } else {
-                zipFile.close();
+                Utils.close(zipFile);
             }
         } catch (Exception e) {
@@ -224,8 +224,8 @@
                 bos.write(buffer, 0, length);
             }
-            bos.close();
+            Utils.close(bos);
             bos = null;
             /* close fos as well to be sure! */
-            fos.close();
+            Utils.close(fos);
             fos = null;
             localFile = new File(destDir, localPath);
@@ -304,5 +304,5 @@
     @Override
     public void close() throws IOException
-    { fs.close(); }
+    { Utils.close(fs); }
     @Override
     public int read() throws IOException
Index: trunk/src/org/openstreetmap/josm/io/NmeaReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/NmeaReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/NmeaReader.java	(revision 5874)
@@ -20,4 +20,5 @@
 import org.openstreetmap.josm.data.gpx.WayPoint;
 import org.openstreetmap.josm.tools.DateUtils;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -176,7 +177,7 @@
         Collection<Collection<WayPoint>> currentTrack = new ArrayList<Collection<WayPoint>>();
 
+        BufferedReader rd = null;
         try {
-            BufferedReader rd =
-                new BufferedReader(new InputStreamReader(source));
+            rd = new BufferedReader(new InputStreamReader(source));
 
             StringBuffer sb = new StringBuffer(1024);
@@ -206,10 +207,11 @@
                 }
             }
-            rd.close();
             currentTrack.add(ps.waypoints);
             data.tracks.add(new ImmutableGpxTrack(currentTrack, Collections.<String, Object>emptyMap()));
 
-        } catch (final IOException e) {
+        } catch (IOException e) {
             // TODO tell user about the problem?
+        } finally {
+            Utils.close(rd);
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/OsmApi.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 5874)
@@ -625,5 +625,5 @@
                         bwr.flush();
                     }
-                    out.close();
+                    Utils.close(out);
                 }
 
Index: trunk/src/org/openstreetmap/josm/io/OsmExporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmExporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmExporter.java	(revision 5874)
@@ -21,4 +21,5 @@
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.tools.Utils;
 
 public class OsmExporter extends FileExporter {
@@ -64,5 +65,5 @@
             if (file.exists()) {
                 tmpFile = new File(file.getPath() + "~");
-                copy(file, tmpFile);
+                Utils.copyFile(file, tmpFile);
             }
 
@@ -75,6 +76,6 @@
             try {
                 w.writeLayer(layer);
-                w.close();
             } finally {
+                Utils.close(w);
                 layer.data.getReadLock().unlock();
             }
@@ -99,5 +100,5 @@
                 // be deleted.  So, restore the backup if we made one.
                 if (tmpFile != null && tmpFile.exists()) {
-                    copy(tmpFile, file);
+                    Utils.copyFile(tmpFile, file);
                 }
             } catch (IOException e2) {
@@ -112,24 +113,3 @@
         }
     }
-
-    private void copy(File src, File dst) throws IOException {
-        FileInputStream srcStream;
-        FileOutputStream dstStream;
-        try {
-            srcStream = new FileInputStream(src);
-            dstStream = new FileOutputStream(dst);
-        } catch (FileNotFoundException e) {
-            JOptionPane.showMessageDialog(Main.parent, tr("Could not back up file. Exception is: {0}", e
-                    .getMessage()), tr("Error"), JOptionPane.ERROR_MESSAGE);
-            return;
-        }
-        byte buf[] = new byte[1 << 16];
-        int len;
-        while ((len = srcStream.read(buf)) != -1) {
-            dstStream.write(buf, 0, len);
-        }
-        srcStream.close();
-        dstStream.close();
-    }
-
 }
Index: trunk/src/org/openstreetmap/josm/io/OsmImporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmImporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmImporter.java	(revision 5874)
@@ -19,4 +19,5 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.gui.util.GuiHelper;
+import org.openstreetmap.josm.tools.Utils;
 
 public class OsmImporter extends FileImporter {
@@ -67,7 +68,5 @@
             throw new IOException(tr("File ''{0}'' does not exist.", file.getName()));
         } finally {
-            if (in != null) {
-                in.close();
-            }
+            Utils.close(in);
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java	(revision 5874)
@@ -18,8 +18,9 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
  * OsmServerBackreferenceReader fetches the primitives from the OSM server which
- * refer to a specific primitive. For a {@link Node}, ways and relations are retrieved
+ * refer to a specific primitive. For a {@link org.openstreetmap.josm.data.osm.Node Node}, ways and relations are retrieved
  * which refer to the node. For a {@link Way} or a {@link Relation}, only relations are
  * read.
@@ -150,10 +151,6 @@
         } finally {
             progressMonitor.finishTask();
-            if (in != null) {
-                try {
-                    in.close();
-                } catch(Exception e) {}
-                activeConnection = null;
-            }
+            Utils.close(in);
+            activeConnection = null;
         }
     }
@@ -188,10 +185,6 @@
         } finally {
             progressMonitor.finishTask();
-            if (in != null) {
-                try {
-                    in.close();
-                } catch(Exception e) {}
-                activeConnection = null;
-            }
+            Utils.close(in);
+            activeConnection = null;
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java	(revision 5874)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -78,10 +79,6 @@
         } finally {
             progressMonitor.finishTask();
-            if (in != null) {
-                try {
-                    in.close();
-                } catch(Exception e) {}
-                activeConnection = null;
-            }
+            Utils.close(in);
+            activeConnection = null;
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java	(revision 5874)
@@ -13,4 +13,5 @@
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.tools.Utils;
 import org.xml.sax.SAXException;
 
@@ -40,11 +41,7 @@
         } finally {
             progressMonitor.finishTask();
-            try {
-                activeConnection = null;
-                if (parser.in != null) {
-                    parser.in.close();
-                    parser.in = null;
-                }
-            } catch(Exception e) {/* ignore it */}
+            activeConnection = null;
+            Utils.close(parser.in);
+            parser.in = null;
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java	(revision 5874)
@@ -15,4 +15,5 @@
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.Utils;
 import org.xml.sax.SAXException;
 
@@ -144,9 +145,5 @@
         } finally {
             progressMonitor.finishTask();
-            if (in!=null) {
-                try {
-                    in.close();
-                } catch(Exception e) {/* ignore this exception */}
-            }
+            Utils.close(in);
             activeConnection = null;
         }
Index: trunk/src/org/openstreetmap/josm/io/OsmWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmWriter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/OsmWriter.java	(revision 5874)
@@ -71,4 +71,5 @@
         header(null);
     }
+    
     public void header(Boolean upload) {
         out.println("<?xml version='1.0' encoding='UTF-8'?>");
@@ -81,4 +82,5 @@
         out.println("' generator='JOSM'>");
     }
+    
     public void footer() {
         out.println("</osm>");
@@ -313,12 +315,3 @@
         }
     }
-
-    public void close() {
-        out.close();
-    }
-
-    @Override
-    public void flush() {
-        out.flush();
-    }
 }
Index: trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java	(revision 5874)
@@ -49,6 +49,9 @@
 
     @Override public void close() throws IOException {
-        in.close();
-        progressMonitor.finishTask();
+        try {
+            in.close();
+        } finally {
+            progressMonitor.finishTask();
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java	(revision 5874)
@@ -10,4 +10,5 @@
 import org.openstreetmap.josm.gui.layer.WMSLayer;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -34,5 +35,5 @@
                 ((WMSLayer)layer).writeExternal(oos);
             } finally {
-                oos.close();
+                Utils.close(oos);
             }
         }
Index: trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java	(revision 5874)
@@ -15,4 +15,5 @@
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -55,5 +56,5 @@
             throw new IllegalDataException(e);
         } finally {
-            ois.close();
+            Utils.close(ois);
         }
         
Index: trunk/src/org/openstreetmap/josm/io/XmlWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/XmlWriter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/XmlWriter.java	(revision 5874)
@@ -2,4 +2,6 @@
 package org.openstreetmap.josm.io;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.HashMap;
@@ -10,7 +12,7 @@
  * @author imi
  */
-public class XmlWriter {
+public class XmlWriter implements Closeable {
 
-    protected PrintWriter out;
+    protected final PrintWriter out;
 
     public XmlWriter(PrintWriter out) {
@@ -18,6 +20,11 @@
     }
 
+    /**
+     * Flushes the stream.
+     */
     public void flush() {
-        out.flush();
+        if (out != null) {
+            out.flush();
+        }
     }
 
@@ -69,3 +76,10 @@
         encoding.put('\t', "&#x9;");
     }
+    
+    @Override
+    public void close() throws IOException {
+        if (out != null) {
+            out.close();
+        }
+    }
 }
Index: trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java	(revision 5874)
@@ -178,5 +178,5 @@
             Utils.copyStream(is, baos);
         } finally {
-            is.close();
+            Utils.close(is);
         }
 
@@ -201,5 +201,5 @@
             return exception.toString();
         } finally {
-            br.close();
+            Utils.close(br);
         }
     }
Index: trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java	(revision 5874)
@@ -101,5 +101,4 @@
         public MarkerWriter(PrintWriter out) {
             super(out);
-            creator = "JOSM Marker export";
         }
 
Index: trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java	(revision 5874)
@@ -247,5 +247,5 @@
             zipOut.putNextEntry(entry);
             writeJos(doc, zipOut);
-            zipOut.close();
+            Utils.close(zipOut);
         } else {
             writeJos(doc, new BufferedOutputStream(out));
Index: trunk/src/org/openstreetmap/josm/plugins/Plugin.java
===================================================================
--- trunk/src/org/openstreetmap/josm/plugins/Plugin.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/plugins/Plugin.java	(revision 5874)
@@ -15,4 +15,5 @@
 import org.openstreetmap.josm.gui.download.DownloadSelection;
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -110,12 +111,17 @@
             pluginDir.mkdirs();
         }
-        FileOutputStream out = new FileOutputStream(new File(pluginDirName, to));
-        InputStream in = getClass().getResourceAsStream(from);
-        byte[] buffer = new byte[8192];
-        for(int len = in.read(buffer); len > 0; len = in.read(buffer)) {
-            out.write(buffer, 0, len);
+        FileOutputStream out = null;
+        InputStream in = null;
+        try {
+            out = new FileOutputStream(new File(pluginDirName, to));
+            in = getClass().getResourceAsStream(from);
+            byte[] buffer = new byte[8192];
+            for(int len = in.read(buffer); len > 0; len = in.read(buffer)) {
+                out.write(buffer, 0, len);
+            }
+        } finally {
+            Utils.close(in);
+            Utils.close(out);
         }
-        in.close();
-        out.close();
     }
 
Index: trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java	(revision 5874)
@@ -129,6 +129,4 @@
                 out.write(buffer, 0, read);
             }
-            out.close();
-            in.close();
         } catch(MalformedURLException e) {
             String msg = tr("Warning: Cannot download plugin ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.", pi.name, pi.downloadlink);
Index: trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
===================================================================
--- trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java	(revision 5874)
@@ -29,4 +29,5 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.LanguageInfo;
+import org.openstreetmap.josm.tools.Utils;
 
 /**
@@ -100,14 +101,6 @@
             throw new PluginException(name, e);
         } finally {
-            if (jar != null) {
-                try {
-                    jar.close();
-                } catch(IOException e) { /* ignore */ }
-            }
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch(IOException e) { /* ignore */ }
-            }
+            Utils.close(jar);
+            Utils.close(fis);
         }
     }
Index: trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
===================================================================
--- trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java	(revision 5874)
@@ -218,6 +218,4 @@
                 out.write(buffer, 0, read);
             }
-            out.close();
-            in.close();
         } catch(MalformedURLException e) {
             if (canceled) return;
@@ -229,4 +227,5 @@
             return;
         } finally {
+            Utils.close(out);
             synchronized(this) {
                 if (connection != null) {
@@ -274,5 +273,5 @@
             if (writer != null) {
                 writer.flush();
-                writer.close();
+                Utils.close(writer);
             }
         }
Index: trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java	(revision 5874)
@@ -256,5 +256,5 @@
                         audioOutputLine.close();
                         audioOutputLine = null;
-                        audioInputStream.close();
+                        Utils.close(audioInputStream);
                         audioInputStream = null;
                         playingUrl = null;
@@ -277,5 +277,5 @@
                             {
                                 if (audioInputStream != null) {
-                                    audioInputStream.close();
+                                    Utils.close(audioInputStream);
                                     audioInputStream = null;
                                 }
Index: trunk/src/org/openstreetmap/josm/tools/AudioUtil.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/AudioUtil.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/AudioUtil.java	(revision 5874)
@@ -33,5 +33,5 @@
                 * audioFormat.getFrameSize() /* bytes per frame */;
             double naturalLength = filesize / bytesPerSecond;
-            audioInputStream.close();
+            Utils.close(audioInputStream);
             double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
             return naturalLength / calibration;
Index: trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java	(revision 5874)
@@ -44,8 +44,16 @@
 
     //http://stuffthathappens.com/blog/2007/10/15/one-more-note-on-uncaught-exception-handlers/
+    /**
+     * Handles the given throwable object
+     * @param t The throwable object
+     */
     public void handle(Throwable t) {
         handleException(t);
     }
 
+    /**
+     * Handles the given exception
+     * @param e the exception
+     */
     public static void handleException(final Throwable e) {
         if (handlingInProgress)
@@ -165,4 +173,9 @@
         }
     }
+    
+    /**
+     * Determines if an exception is currently being handled
+     * @return {@code true} if an exception is currently being handled, {@code false} otherwise
+     */
     public static boolean exceptionHandlingInProgress() {
         return handlingInProgress;
@@ -180,5 +193,5 @@
             GZIPOutputStream gzip = new GZIPOutputStream(out);
             gzip.write(debugText.getBytes("UTF-8"));
-            gzip.close();
+            Utils.close(gzip);
     
             return new URL("http://josm.openstreetmap.de/josmticket?" +
Index: trunk/src/org/openstreetmap/josm/tools/I18n.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/I18n.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/I18n.java	(revision 5874)
@@ -422,24 +422,11 @@
                     load(jar, jarTrans, true);
             }
-        }
-        catch(IOException e)
-        {
-        }
-        finally
-        {
-            try
-            {
-                if(jar != null)
-                    jar.close();
-                if(fis != null)
-                    fis.close();
-                if(jarTrans != null)
-                    jarTrans.close();
-                if(fisTrans != null)
-                    fisTrans.close();
-            }
-            catch(IOException e)
-            {
-            }
+        } catch(IOException e) {
+            // Ignore
+        } finally {
+            Utils.close(jar);
+            Utils.close(fis);
+            Utils.close(jarTrans);
+            Utils.close(fisTrans);
         }
     }
@@ -482,6 +469,6 @@
             // Ignore exception
         } finally {
-            if (trStream != null) try {trStream.close();} catch(IOException e) {}
-            if (enStream != null) try {enStream.close();} catch(IOException e) {}
+            Utils.close(trStream);
+            Utils.close(enStream);
         }
         return false;
Index: trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 5874)
@@ -556,7 +556,5 @@
                     }
                 } finally {
-                    if (is != null) {
-                        is.close();
-                    }
+                    Utils.close(is);
                 }
             }
@@ -564,10 +562,5 @@
             System.err.println(tr("Warning: failed to handle zip file ''{0}''. Exception was: {1}", archive.getName(), e.toString()));
         } finally {
-            if (zipFile != null) {
-                try {
-                    zipFile.close();
-                } catch (IOException ex) {
-                }
-            }
+            Utils.close(zipFile);
         }
         return null;
Index: trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java	(revision 5874)
@@ -94,5 +94,5 @@
                 BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                 String line = Utils.strip(input.readLine());
-                input.close();
+                Utils.close(input);
                 if (line != null && !line.isEmpty()) {
                     line = line.replaceAll("\"+","");
Index: trunk/src/org/openstreetmap/josm/tools/Utils.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 5874)
@@ -11,14 +11,17 @@
 import java.awt.datatransfer.UnsupportedFlavorException;
 import java.io.BufferedReader;
+import java.io.Closeable;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.channels.FileChannel;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -30,4 +33,5 @@
 import java.util.Iterator;
 import java.util.List;
+import java.util.zip.ZipFile;
 
 import org.openstreetmap.josm.Main;
@@ -237,4 +241,30 @@
     }
 
+    /**
+     * Simple file copy function that will overwrite the target file.<br/>
+     * Taken from <a href="http://www.rgagnon.com/javadetails/java-0064.html">this article</a> (CC-NC-BY-SA)
+     * @param in The source file
+     * @param out The destination file
+     * @throws IOException If any I/O error occurs
+     */
+    public static void copyFile(File in, File out) throws IOException  {
+        // TODO: remove this function when we move to Java 7 (use Files.copy instead) 
+        FileInputStream inStream = null;
+        FileOutputStream outStream = null;
+        try {
+            inStream = new FileInputStream(in);
+            outStream = new FileOutputStream(out);
+            FileChannel inChannel = inStream.getChannel();
+            inChannel.transferTo(0, inChannel.size(), outStream.getChannel());
+        }
+        catch (IOException e) {
+            throw e;
+        }
+        finally {
+            close(outStream);
+            close(inStream);
+        }
+    }
+    
     public static int copyStream(InputStream source, OutputStream destination) throws IOException {
         int count = 0;
@@ -264,41 +294,27 @@
 
     /**
-     * <p>Utility method for closing an input stream.</p>
+     * <p>Utility method for closing a {@link Closeable} object.</p>
      *
-     * @param is the input stream. May be null.
-     */
-    public static void close(InputStream is){
-        if (is == null) return;
+     * @param c the closeable object. May be null.
+     */
+    public static void close(Closeable c) {
+        if (c == null) return;
         try {
-            is.close();
-        } catch(IOException e){
+            c.close();
+        } catch(IOException e) {
             // ignore
         }
     }
-
-    /**
-     * <p>Utility method for closing an output stream.</p>
+    
+    /**
+     * <p>Utility method for closing a {@link ZipFile}.</p>
      *
-     * @param os the output stream. May be null.
-     */
-    public static void close(OutputStream os){
-        if (os == null) return;
+     * @param zip the zip file. May be null.
+     */
+    public static void close(ZipFile zip) {
+        if (zip == null) return;
         try {
-            os.close();
-        } catch(IOException e){
-            // ignore
-        }
-    }
-
-    /**
-     * <p>Utility method for closing a reader.</p>
-     *
-     * @param reader the reader. May be null.
-     */
-    public static void close(Reader reader){
-        if (reader == null) return;
-        try {
-            reader.close();
-        } catch(IOException e){
+            zip.close();
+        } catch(IOException e) {
             // ignore
         }
Index: trunk/src/org/openstreetmap/josm/tools/WikiReader.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/WikiReader.java	(revision 5873)
+++ trunk/src/org/openstreetmap/josm/tools/WikiReader.java	(revision 5874)
@@ -4,5 +4,4 @@
 import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 
@@ -41,5 +40,5 @@
             return readNormal(in);
         } finally {
-            in.close();
+            Utils.close(in);
         }
     }
@@ -63,5 +62,5 @@
             return readFromTrac(in);
         } finally {
-            in.close();
+            Utils.close(in);
         }
     }
