Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java	(revision 30738)
@@ -1,4 +1,24 @@
 // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
 package cadastre_fr;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+
 /**
  * This class handles the WMS layer cache mechanism. The design is oriented for a good performance (no
@@ -10,16 +30,4 @@
  * is inserted before each append and an exception is raised at objects read).
  */
-
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import javax.swing.JDialog;
-import javax.swing.JOptionPane;
-import org.openstreetmap.josm.Main;
-
 public class CacheControl implements Runnable {
 
@@ -32,4 +40,5 @@
             super(out);
         }
+        @Override
         protected void writeStreamHeader() throws IOException {
             reset();
@@ -40,5 +49,4 @@
 
     public static int cacheSize = 500;
-
 
     public WMSLayer wmsLayer = null;
@@ -141,9 +149,8 @@
     public boolean loadCache(File file, int currentLambertZone) {
         boolean successfulRead = false;
-        FileInputStream fis = null;
-        ObjectInputStream ois = null;
-        try {
-            fis = new FileInputStream(file);
-            ois = new ObjectInputStream(fis);
+        try (
+            FileInputStream fis = new FileInputStream(file);
+            ObjectInputStream ois = new ObjectInputStream(fis);
+        ) {
             successfulRead = wmsLayer.read(file, ois, currentLambertZone);
         } catch (Exception ex) {
@@ -151,11 +158,4 @@
             JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."), tr("Error"), JOptionPane.ERROR_MESSAGE);
             return false;
-        } finally {
-            try {
-                ois.close();
-                fis.close();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
         }
         if (successfulRead && wmsLayer.isRaster()) {
@@ -165,5 +165,4 @@
         return successfulRead;
     }
-
 
     public synchronized void saveCache(GeorefImage image) {
@@ -177,4 +176,5 @@
      * Thread saving the grabbed images in background.
      */
+    @Override
     public synchronized void run() {
         for (;;) {
@@ -186,21 +186,21 @@
                 try {
                     if (file.exists()) {
-                        ObjectOutputStreamAppend oos = new ObjectOutputStreamAppend(
-                                new BufferedOutputStream(new FileOutputStream(file, true)));
-                        for (int i=0; i < size; i++) {
-                            oos.writeObject(imagesToSave.get(i));
+                        try (ObjectOutputStreamAppend oos = new ObjectOutputStreamAppend(
+                                new BufferedOutputStream(new FileOutputStream(file, true)))) {
+                            for (int i=0; i < size; i++) {
+                                oos.writeObject(imagesToSave.get(i));
+                            }
                         }
-                        oos.close();
                     } else {
-                        ObjectOutputStream oos = new ObjectOutputStream(
-                                new BufferedOutputStream(new FileOutputStream(file)));
-                        wmsLayer.write(file, oos);
-                        for (int i=0; i < size; i++) {
-                            oos.writeObject(imagesToSave.get(i));
+                        try (ObjectOutputStream oos = new ObjectOutputStream(
+                                new BufferedOutputStream(new FileOutputStream(file)))) {
+                            wmsLayer.write(file, oos);
+                            for (int i=0; i < size; i++) {
+                                oos.writeObject(imagesToSave.get(i));
+                            }
                         }
-                        oos.close();
                     }
                 } catch (IOException e) {
-                    e.printStackTrace(System.out);
+                    Main.error(e);
                 }
                 imagesLock.lock();
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java	(revision 30738)
@@ -22,6 +22,6 @@
     private CadastreInterface wmsInterface = new CadastreInterface();
 
-    public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException {
-
+    public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax)
+            throws IOException, OsmTransferException {
         try {
             URL url = null;
@@ -88,8 +88,7 @@
         wmsInterface.urlConn.setRequestMethod("GET");
         wmsInterface.setCookie();
-        InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE);
-        BufferedImage img = ImageIO.read(is);
-        is.close();
-        return img;
+        try (InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE)) {
+            return ImageIO.read(is);
+        }
     }
 
@@ -97,4 +96,3 @@
         return wmsInterface;
     }
-
 }
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java	(revision 30738)
@@ -229,5 +229,5 @@
             }
             if (Main.isDebugEnabled()) {
-            	Main.debug(lines);
+                Main.debug(lines);
             }
         } catch (MalformedURLException e) {
@@ -284,14 +284,14 @@
             urlConn.setDoInput(true);
             setCookie();
-            OutputStream wr = urlConn.getOutputStream();
-            wr.write(content.getBytes());
-            System.out.println("POST "+content);
-            wr.flush();
-            wr.close();
-            BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
-            while ((ln = rd.readLine()) != null) {
-                lines += ln;
-            }
-            rd.close();
+            try (OutputStream wr = urlConn.getOutputStream()) {
+                wr.write(content.getBytes());
+                Main.info("POST "+content);
+                wr.flush();
+            }
+            try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) {
+                while ((ln = rd.readLine()) != null) {
+                    lines += ln;
+                }
+            }
             urlConn.disconnect();
             if (lines != null) {
@@ -371,15 +371,14 @@
             setCookie(urlConn2);
             urlConn2.connect();
-            System.out.println("GET "+getAllImagesURL);
-            BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream()));
-            while ((ln = rd.readLine()) != null) {
-                lines += ln;
-            }
-            rd.close();
+            Main.info("GET "+getAllImagesURL);
+            try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream()))) {
+                while ((ln = rd.readLine()) != null) {
+                    lines += ln;
+                }
+            }
             urlConn2.disconnect();
-            //System.out.println("GET="+lines);
         } catch (IOException e) {
             listOfFeuilles.clear();
-            e.printStackTrace();
+            Main.error(e);
         }
         return lines;
@@ -483,9 +482,9 @@
         }
         System.out.println("GET "+searchFormURL);
-        BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
-        while ((ln = in.readLine()) != null) {
-            line += ln;
-        }
-        in.close();
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) {
+            while ((ln = in.readLine()) != null) {
+                line += ln;
+            }
+        }
         urlConn.disconnect();
         parseBBoxCommune(wmsLayer, line);
@@ -511,5 +510,5 @@
 
     private void parseGeoreferences(WMSLayer wmsLayer, String input) {
-        /* commented since cadastre WMS changes mid july 2013 
+        /* commented since cadastre WMS changes mid july 2013
          * until new GeoBox coordinates parsing is solved */
 //        if (input.lastIndexOf(cBBoxCommunStart) != -1) {
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionExporter.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionExporter.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionExporter.java	(revision 30738)
@@ -30,11 +30,11 @@
     }
 
-	@Override
-	public Collection<Layer> getDependencies() {
+    @Override
+    public Collection<Layer> getDependencies() {
         return Collections.emptySet();
-	}
+    }
 
-	@Override
-	public Component getExportPanel() {
+    @Override
+    public Component getExportPanel() {
         final JPanel p = new JPanel(new GridBagLayout());
         export = new JCheckBox();
@@ -46,18 +46,18 @@
         p.add(GBC.glue(1,0), GBC.std().fill(GBC.HORIZONTAL));
         return p;
-	}
+    }
 
-	@Override
-	public boolean shallExport() {
+    @Override
+    public boolean shallExport() {
         return export.isSelected();
-	}
+    }
 
-	@Override
-	public boolean requiresZip() {
-		return false;
-	}
+    @Override
+    public boolean requiresZip() {
+        return false;
+    }
 
-	@Override
-	public Element export(ExportSupport support) throws IOException {
+    @Override
+    public Element export(ExportSupport support) throws IOException {
         Element layerEl = support.createElement("layer");
         layerEl.setAttribute("type", "cadastre-fr");
@@ -76,5 +76,5 @@
         file.appendChild(support.createTextNode(url.toString()));
         return layerEl;
-	}
+    }
 
 }
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionImporter.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionImporter.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreSessionImporter.java	(revision 30738)
@@ -22,8 +22,8 @@
 public class CadastreSessionImporter implements SessionLayerImporter{
 
-	@Override
-	public Layer load(Element elem, ImportSupport support,
-			ProgressMonitor progressMonitor) throws IOException,
-			IllegalDataException {
+    @Override
+    public Layer load(Element elem, ImportSupport support,
+            ProgressMonitor progressMonitor) throws IOException,
+            IllegalDataException {
         String version = elem.getAttribute("version");
         if (!"0.1".equals(version)) {
@@ -41,5 +41,5 @@
             fileStr = URLDecoder.decode(fileStr, "UTF-8");
             fileStr = fileStr.substring(fileStr.indexOf(":/")+2);
-    		String filename = fileStr.substring(fileStr.lastIndexOf("/")+1,fileStr.length());
+            String filename = fileStr.substring(fileStr.lastIndexOf("/")+1,fileStr.length());
             String ext = (filename.lastIndexOf(".")==-1)?"":filename.substring(filename.lastIndexOf(".")+1,filename.length());
             // create layer and load cache
@@ -60,5 +60,5 @@
             throw new RuntimeException(e);
         }
-	}
+    }
 
 }
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java	(revision 30738)
@@ -43,5 +43,7 @@
     private static String errorMessage;
 
-
+    /**
+     * Constructs a new {@code DownloadSVGBuilding}.
+     */
     public DownloadSVGBuilding(WMSLayer wmsLayer) {
         super(tr("Downloading {0}", wmsLayer.getName()));
@@ -240,25 +242,22 @@
         wmsInterface.urlConn.setRequestMethod("GET");
         wmsInterface.setCookie();
-        InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE);
         File file = new File(CadastrePlugin.cacheDir + "building.svg");
         String svg = new String();
-        try {
+        try (InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE)) {
             if (file.exists())
                 file.delete();
-            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true));
-            InputStreamReader isr =new InputStreamReader(is);
-            BufferedReader br = new BufferedReader(isr);
-            String line="";
-            while ( null!=(line=br.readLine())){
-                line += "\n";
-                bos.write(line.getBytes());
-                svg += line;
-            }
-            br.close();
-            bos.close();
+            try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true));
+                 InputStreamReader isr = new InputStreamReader(is);
+                 BufferedReader br = new BufferedReader(isr)) {
+                String line="";
+                while ( null!=(line=br.readLine())){
+                    line += "\n";
+                    bos.write(line.getBytes());
+                    svg += line;
+                }
+            }
         } catch (IOException e) {
-            e.printStackTrace(System.out);
-        }
-        is.close();
+            Main.error(e);
+        }
         return svg;
     }
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java	(revision 30738)
@@ -47,4 +47,7 @@
     private static String errorMessage;
 
+    /**
+     * Constructs a new {@code DownloadSVGTask}.
+     */
     public DownloadSVGTask(WMSLayer wmsLayer) {
         super(tr("Downloading {0}", wmsLayer.getName()));
@@ -194,25 +197,22 @@
         wmsInterface.urlConn.setRequestMethod("GET");
         wmsInterface.setCookie();
-        InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE);
         File file = new File(CadastrePlugin.cacheDir + "boundary.svg");
         String svg = new String();
-        try {
+        try (InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE)) {
             if (file.exists())
                 file.delete();
-            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true));
-            InputStreamReader isr =new InputStreamReader(is);
-            BufferedReader br = new BufferedReader(isr);
-            String line="";
-            while ( null!=(line=br.readLine())){
-                line += "\n";
-                bos.write(line.getBytes());
-                svg += line;
+            try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, true));
+                 InputStreamReader isr =new InputStreamReader(is);
+                 BufferedReader br = new BufferedReader(isr)) {
+                String line="";
+                while ( null!=(line=br.readLine())){
+                    line += "\n";
+                    bos.write(line.getBytes());
+                    svg += line;
+                }
             }
-            br.close();
-            bos.close();
         } catch (IOException e) {
-            e.printStackTrace(System.out);
-        }
-        is.close();
+            Main.error(e);
+        }
         return svg;
     }
Index: applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
===================================================================
--- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 30737)
+++ applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 30738)
@@ -133,5 +133,5 @@
         // if the layer is currently saving the images in the cache, wait until it's finished
         if(grabThread != null)
-        		grabThread.cancel();
+                grabThread.cancel();
         grabThread = null;
         super.destroy();
