Skip to content

Commit

Permalink
ensure .poi file well closed
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrichet committed Sep 22, 2023
1 parent bde06ec commit bee7f6d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
10 changes: 1 addition & 9 deletions src/main/java/org/funz/Telemac/TelemacCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ protected int runCommand() throws Exception {
}
if (file.isFile() && file.getName().endsWith(".poi")) {
try {
Properties poi = new Properties();
poi.load(new FileInputStream(file));

Stream<Entry<Object, Object>> stream = poi.entrySet().stream();
Map<String, String> m = stream.collect(Collectors.toMap(
e -> String.valueOf(e.getKey()),
e -> String.valueOf(e.getValue())));

pois.putAll(m);
pois.putAll(TelemacHelper.readPOI(file));
} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/funz/Telemac/TelemacHelper.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package org.funz.Telemac;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.fudaa.dodico.ef.operation.EfLineSingleIntersectFinder;
Expand Down Expand Up @@ -131,6 +136,26 @@ public static String[] readFichiersDe(File cas, String what) {
return fde.toArray(new String[fde.size()]);
}

public static Map<String, String> readPOI(File poifile) throws Exception {
Map<String, String> m = new HashMap<String, String>();
FileInputStream fs =null;
Properties poi = new Properties();
fs = new FileInputStream(poifile);
poi.load(fs);

Stream<Entry<Object, Object>> stream = poi.entrySet().stream();
m = stream.collect(Collectors.toMap(
e -> String.valueOf(e.getKey()),
e -> String.valueOf(e.getValue())));
if (fs != null)
try {
fs.close();
} catch (Exception e) {
e.printStackTrace();
}
return m;
}

static Map<String, double[][]> extractPOIfromCASRES(File cas, Properties poi) throws Exception {
return extractPOIfromRES(new File(cas.getAbsoluteFile().getParentFile(), readFichiersDe(cas, "RESULT")[0]), poi);
}
Expand Down
21 changes: 3 additions & 18 deletions src/main/java/org/funz/Telemac/TelemacIOPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.funz.parameter.OutputFunctionExpression;
import org.funz.parameter.SyntaxRules;
import org.funz.util.Parser;

import org.funz.parameter.InputFile;

public class TelemacIOPlugin extends ExtendedIOPlugin {
Expand Down Expand Up @@ -74,15 +75,7 @@ public void setInputFiles(File... inputfiles) {
}
if (file.isFile() && file.getName().endsWith(".poi")) {
try {
Properties poi = new Properties();
poi.load(new FileInputStream(file));

Stream<Entry<Object, Object>> stream = poi.entrySet().stream();
Map<String, String> m = stream.collect(Collectors.toMap(
e -> String.valueOf(e.getKey()),
e -> String.valueOf(e.getValue())));

pois.putAll(m);
pois.putAll(TelemacHelper.readPOI(file));
} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down Expand Up @@ -134,15 +127,7 @@ public boolean accept(File pathname) {
}
if (file.isFile() && file.getName().endsWith(".poi")) {
try {
Properties poi = new Properties();
poi.load(new FileInputStream(file));

Stream<Entry<Object, Object>> stream = poi.entrySet().stream();
Map<String, String> m = stream.collect(Collectors.toMap(
e -> String.valueOf(e.getKey()),
e -> String.valueOf(e.getValue())));

pois.putAll(m);
pois.putAll(TelemacHelper.readPOI(file));
} catch (Exception ex) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Expand Down

0 comments on commit bee7f6d

Please sign in to comment.