Author: chatellier Date: 2011-06-15 09:07:27 +0000 (Wed, 15 Jun 2011) New Revision: 3395 Log: Fix stream closing Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2011-06-15 09:01:01 UTC (rev 3394) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationStorage.java 2011-06-15 09:07:27 UTC (rev 3395) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2005 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -37,6 +37,7 @@ import java.util.Properties; import org.apache.commons.collections.map.ReferenceMap; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; @@ -256,16 +257,18 @@ * @param control l'objet control de la simulation courante */ public void saveControl(SimulationControl control) { + FileOutputStream out = null; try { Properties prop = control.getProperties(); File file = getSimulationControlFile(); - FileOutputStream out = new FileOutputStream(file); + out = new FileOutputStream(file); prop.store(out, "Control"); - out.close(); } catch (Exception eee) { // juste un log, car la sauvegarde d'un control ne doit jamais echouer // car simplement utilise pour indique l'etat de simulation log.warn("Can't save control", eee); + } finally { + IOUtils.closeQuietly(out); } } @@ -296,11 +299,12 @@ try { Properties prop = new Properties(); if (controlFile.exists()) { - FileInputStream in = new FileInputStream(controlFile); + FileInputStream in = null; try { + in = new FileInputStream(controlFile); prop.load(in); } finally { - in.close(); + IOUtils.closeQuietly(in); } for (String e : exclude) { prop.remove(e); @@ -326,15 +330,19 @@ this.parameter = parameter; if (parameter != null) { Properties prop = parameter.toProperties(); - log.info("DEBUG: store param: " + prop); + if (log.isDebugEnabled()) { + log.debug("Store params: " + prop); + } File file = getSimulationParametersFile(); + FileOutputStream out = null; try { - FileOutputStream out = new FileOutputStream(file); + out = new FileOutputStream(file); prop.store(out, "Parameters"); - out.close(); } catch (IOException eee) { throw new IsisFishRuntimeException(_( "isisfish.error.save.simulation.parameters", file), eee); + } finally { + IOUtils.closeQuietly(out); } } } @@ -355,14 +363,16 @@ + file.getAbsolutePath()); } + FileInputStream in = null; try { - FileInputStream in = new FileInputStream(file); + in = new FileInputStream(file); prop.load(in); - in.close(); parameter = new SimulationParameterImpl(); parameter.fromProperties(prop); } catch (IOException eee) { throw new IsisFishRuntimeException(_("isisfish.error.read.simulation.parameters", file), eee); + } finally { + IOUtils.closeQuietly(in); } } return this.parameter; @@ -384,14 +394,16 @@ Properties prop = new Properties(); File file = getSimulationParametersFile(); + FileInputStream in = null; try { - FileInputStream in = new FileInputStream(file); + in = new FileInputStream(file); prop.load(in); - in.close(); parameter = new SimulationParameterImpl(); parameter.fromProperties(prop); } catch (IOException eee) { throw new IsisFishRuntimeException(_("isisfish.error.read.simulation.parameters", file), eee); + } finally { + IOUtils.closeQuietly(in); } return this.parameter; }