Author: chatellier Date: 2009-08-26 12:25:46 +0000 (Wed, 26 Aug 2009) New Revision: 2531 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java Log: Ferme les flux ?\195?\160 la lecture/?\195?\169criture du fichier de sauvegarde des simulations en cours. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-08-26 12:24:48 UTC (rev 2530) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationMonitor.java 2009-08-26 12:25:46 UTC (rev 2531) @@ -24,6 +24,8 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.rmi.RemoteException; import java.util.Collection; import java.util.Comparator; @@ -153,10 +155,12 @@ public void reloadConfig(final SimulationService service) { if (monitorFile.canRead()) { + InputStream is = null; try { - properties.load(new FileInputStream(monitorFile)); + is = new FileInputStream(monitorFile); + properties.load(is); - // in a thead + // in a thread // don't temporize UI loading new Thread() { public void run() { @@ -168,6 +172,17 @@ log.error("Can't reload monitor file", e); } } + finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Can't close monitor file", e); + } + } + } + } } } @@ -284,7 +299,9 @@ monitorValue += MONITORFILESEPARATOR + planList; properties.put(monitorKey, monitorValue); + OutputStream out = null; try { + out = new FileOutputStream(monitorFile); properties.store(new FileOutputStream(monitorFile), "Simulation added at " + new Date()); } catch (IOException e) { @@ -292,6 +309,17 @@ log.error("Can't save monitor file", e); } } + finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Can't close monitor file", e); + } + } + } + } if (log.isInfoEnabled()) { log.info("Saving simulation " + monitorKey + " as started"); @@ -322,18 +350,31 @@ String monitorKey = job.getId(); properties.remove(monitorKey); + OutputStream out = null; try { if (properties.isEmpty()) { monitorFile.delete(); } else { - properties.store(new FileOutputStream(monitorFile), - "Simulation delete at " + new Date()); + out = new FileOutputStream(monitorFile); + properties.store(out, "Simulation delete at " + new Date()); + } } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Can't save monitor file", e); } } + finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Can't close monitor file", e); + } + } + } if (log.isInfoEnabled()) { log.info("Saving simulation " + monitorKey + " as stopped");