summaryrefslogtreecommitdiff
path: root/nlpsolver
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-13 00:11:59 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-13 06:56:56 +0000
commit88bfc90de9bf03c8dbce9f26de079a9fd1d83146 (patch)
tree3ec4b92cb98368a1fbf3e9ea4339352af752f57d /nlpsolver
parente77235e87ef8554ba38ce4454f2f99bd62dd5824 (diff)
nlpsolver: ensure that the stream is cleaned up before the method returns
Change-Id: I081194d802bd835285bdc37fbef55f229f1185dc Reviewed-on: https://gerrit.libreoffice.org/11940 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'nlpsolver')
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java
index 36e4ebba91a8..913ee64f1574 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalFile.java
@@ -87,9 +87,14 @@ public class GlobalFile {
*/
public static void saveStringToFile(String inStr, String fileStr) throws Exception{
new File(new File(fileStr).getParent()).mkdirs();
- FileOutputStream pspOutputStream = new FileOutputStream(new File(fileStr));
- pspOutputStream.write(inStr.getBytes());
- pspOutputStream.close();
+ FileOutputStream pspOutputStream = null;
+ try {
+ pspOutputStream = new FileOutputStream(new File(fileStr));
+ pspOutputStream.write(inStr.getBytes());
+ } finally {
+ if (pspOutputStream != null)
+ pspOutputStream.close();
+ }
}
/**
@@ -100,12 +105,18 @@ public class GlobalFile {
*/
public static String getStringFromFile(String fileStr) throws Exception {
String getStr = null;
- FileInputStream pspInputStream = new FileInputStream(fileStr);
- byte[] pspFileBuffer = new byte[pspInputStream.available()];
- pspInputStream.read(pspFileBuffer);
- pspInputStream.close();
- getStr = new String(pspFileBuffer);
- return(getStr);
+ FileInputStream pspInputStream = null;
+ try {
+ pspInputStream = new FileInputStream(fileStr);
+ byte[] pspFileBuffer = new byte[pspInputStream.available()];
+ pspInputStream.read(pspFileBuffer);
+
+ getStr = new String(pspFileBuffer);
+ } finally {
+ if (pspInputStream != null)
+ pspInputStream.close();
+ }
+ return getStr;
}
/**